【问题标题】:PHP email submit form receiver not receiving the correct sendr email addressPHP电子邮件提交表单接收者未收到正确的发件人电子邮件地址
【发布时间】:2012-08-31 11:55:21
【问题描述】:

我试图找出提交表单的 PHP 代码的问题,我正在为我的朋友做。它正在发送电子邮件,但问题是接收者收到了一个非常奇怪的电子邮件地址。我附上一张图片来仔细看看。

我的 PHP 代码是:

<?php 
    $error = false;
    $sent = false;

    if(isset($_Post['name'])) {
        if(empty($_Post['name']) || empty($_Post['email']) ||  empty($_Post['comments'])) {
            $error = true;
        } else {

        $to = "linardsberzins@gmail.com";

        $name = trim($_Post['name']);
        $email = trim($_Post['email']);
        $comments = trim($_Post['comments']);

        $subject = "Contact Form";

        $messages =  "Name: $name \r\n Email: $email \r\n Comments: $comments";

        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= "From:" . $name . "\r\n";
        $mailsent = mail($to, $subject, $messages, $headers);

        if($mailsent) {
            $sent = true;
        }
    }
}
?>

非常感谢

【问题讨论】:

  • 您在电子邮件中收到的电子邮件是什么?
  • 你的意思是$_POST而不是$_Post

标签: php forms email


【解决方案1】:

应该是这样的Sender &lt;HIS@EXAMPLE.COM&gt;:

 $headers .= 'From: '.$name.' <'.$email.'>' . "\r\n";

【讨论】:

  • 就是这个,谢谢
【解决方案2】:

尝试将标题添加到电子邮件中,就像 PHP mail Manual 示例 2 中的这样

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

如果您希望它来自带有名称的电子邮件,这将起作用

$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";

【讨论】:

    【解决方案3】:

    将此添加到您的标题

    $headers .= "Reply-To: $replyEmail\r\n";
    

    【讨论】:

      【解决方案4】:

      From: 标头应包含电子邮件地址和姓名,例如

      "From:My Display Name<mydisplayname@gmail.com>\r\n"
      

      【讨论】:

        【解决方案5】:
        <?php 
            $error = false;
            $sent = false;
        
            if(isset($_Post['name'])) {
                if(empty($_Post['name']) || empty($_Post['email']) ||  empty($_Post['comments'])) {
                    $error = true;
                } else {
        
                $to = "linardsberzins@gmail.com";
        
                $name = trim($_Post['name']);
                $email = trim($_Post['email']);
                $comments = trim($_Post['comments']);
        
                $subject = "Contact Form";
        
                $messages =  "Name: $name \r\n Email: $email \r\n Comments: $comments";
        
                $headers  = 'MIME-Version: 1.0' . "\r\n";
                $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                $headers .= 'From: '.$name.' <sender@example.com>' . "\r\n";
                $mailsent = mail($to, $subject, $messages, $headers);
        
                if($mailsent) {
                    $sent = true;
                }
            }
        }
        ?>
        

        试试这个。只需更改标题即可。

        $headers .= 'From: '.$name.' <sender@example.com>' . "\r\n";
        

        【讨论】:

          【解决方案6】:

          嗨,这不是一个错误。如果您提供SENDER EMAIL,那么它将显示发件人的电子邮件地址而不是这个。否则它将使用我们的托管地址。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-01-09
            • 1970-01-01
            • 2013-08-16
            • 1970-01-01
            相关资源
            最近更新 更多