我试图找出提交表单的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;
}
}
}
?>
非常感谢
答案 0 :(得分:7)
应该是这样Sender <HIS@EXAMPLE.COM>
:
$headers .= 'From: '.$name.' <'.$email.'>' . "\r\n";
答案 1 :(得分: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";
答案 2 :(得分:2)
将此添加到标题
$headers .= "Reply-To: $replyEmail\r\n";
答案 3 :(得分:2)
From:标题应包含电子邮件地址和名称,例如
"From:My Display Name<mydisplayname@gmail.com>\r\n"
答案 4 :(得分:2)
<?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";
答案 5 :(得分:0)
嗨这不是错误..如果你提供SENDER EMAIL
那么它将显示发件人的电子邮件地址而不是这个..否则它将需要我们的托管地址。