我的代码是:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$messagesubject = $_POST['subject'];
$text = $_POST['text'];
$to = "name@email.com";
$subject = 'Message from a site visitor '.$name;
$content = 'Name: '.$name."\r\n";
$content .= 'E-mail: '.$email."\r\n";
$content .= 'Subject: '.$messagesubject."\r\n";
$content .= 'Message: '.$text."\r\n";
$headers .= 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
";
$send_contact=mail($to,$subject,$headers,$content);
if($send_contact){
echo "Thank you!";
}
else {
echo "ERROR";
}
?>
我收到一封邮件,但发件人地址(From)是从托管服务器写的我的电子邮件地址。如果我添加$ header(我在$headers = 'From: '.$field_email."\r\n"; ")
创建了这样的标题:mail()
,而不是我收到任何邮件......
我做错了什么?我是这个
的初学者答案 0 :(得分:0)
电子邮件中有效的From:标头必须包含有效的电子邮件地址:
From: <someone@somewhere.xxx>
请注意括号内的括号。您还可以添加其他文字:
From: Someone Important <someone@somewhere.xxx>
答案 1 :(得分:0)
好吧,正如手册所说(http://php.net/manual/en/function.mail.php)邮件功能变量是这样的:
mail($to, $subject, $message, $headers);
你看起来像那样:
mail($to, $subject, $headers, $message);
切换它,你应该得到你想要的东西:)