0

我正在使用 msmtp 和 gmail 在我的 php Web 应用程序中发送电子邮件,在 Ubuntu 上的 localhost 开发中。
当我向我发送电子邮件和收到电子邮件时,它都有效。但是在后一种情况下,即当我向我发送电子邮件时,我看不到发件人的地址电子邮件,但我看到了我,我相信因为实际上是我发送给我的邮件服务器。

收到邮件时如何查看发件人的邮件地址?

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>Contact Me</title>
</head>

<body>
    <h1>Contact Me</h1>
    <?php # Script 11.1 - email.php

    // Check for form submission:
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {

        // Minimal form validation:
        if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['comments'])) {

            // Create the body:
            $body = "Name: {$_POST['name']}\n\nComments: {$_POST['comments']}";

            // Make it no longer than 70 characters long:
            $body = wordwrap($body, 70);

            // Send the email:
            mail('myemail@gmail.com', 'Contact Form Submission', $body, "From: {$_POST['email']}");

            // Print a message:
            echo '<p><em>Thank you for contacting me. I will reply some day.</em></p>';

            // Clear $_POST (so that the form's not sticky):
            $_POST = [];
        } else {
            echo '<p style="font-weight: bold; color: #C00">Please fill out the form completely.</p>';
        }
    } // End of main isset() IF.

    // Create the HTML form:
    ?>
    <p>Please fill out this form to contact me.</p>
    <form action="email.php" method="post">
        <p>Name: <input type="text" name="name" size="30" maxlength="60" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>"></p>
        <p>Email Address: <input type="email" name="email" size="30" maxlength="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"></p>
        <p>Comments: <textarea name="comments" rows="5" cols="30"><?php if (isset($_POST['comments'])) echo $_POST['comments']; ?></textarea></p>
        <p><input type="submit" name="submit" value="Send!"></p>
    </form>
</body>

</html>
4

0 回答 0