我是新来的php和stackoverflow,我想弄清楚一个简单的网站联系表格。我的表单和电子邮件功能正常,但我有一个唠叨的问题,我找不出来。php的邮件头vs网站头的电子邮件
发送邮件时,发件人发送的邮件是[email protected],这是我的服务器。当我将电子邮件指向我的基于域名的电子邮件帐户时,他们不会收到我的收件箱,我敢打赌,垃圾邮件过滤器正在阻止奇怪的电子邮件地址。所以我尝试将它发送到我的Gmail收件箱,它可以正常工作,但我不会定期查看该电子邮件。我宁愿让它进入我的基于域的电子邮件帐户。
所以,我正在寻找一种方法来编辑'从'电子邮件地址。我希望它使用真实的电子邮件地址,而不是用户/服务器,我的或发送它的人会更好。这里有一些尝试和我目前有的尝试,但都没有成功。
几次尝试:
试图拉输入的电子邮件地址发送我的。
//$mailheader = "From: ".$_POST["email"]."\r\n";
//$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
这是另一次尝试。
//$mailheaders = "From: [email protected]\r\nReply-To: [email protected]";
我目前有:
<?
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$security = $_POST['security'];
$to = "[email protected]";
$subject = "Contact Message from Website";
$mailheaders = "From: [email protected]\r\nReply-To: [email protected]";
$message = "A visitor of exampledomain.com has submitted the following message.\n\nName: $name\n\nEmail: $email\n\nPhone: $phone\n\nMessage: $message";
if ($security=="10") {
mail($to,$subject,$message,$mailheaders);
header("Location:contact.php?s=1");
}
else {
header("Location:contact.php?s=2");
}
?>
其次建议。最后的尝试仍然没有工作...
<?
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$security = $_POST['security'];
$to = "[email protected]";
$subject = "Contact Message from Website";
$message = "A visitor of exampledomain.com has submitted the following message.\n\nName: $name\n\nEmail: $email\n\nPhone: $phone\n\nMessage: $message";
$mailheaders = "From: [email protected]\r\nReply-To: [email protected]";
if ($security=="10") {
mail($to,$subject,$message,$mailheaders);
header("Location:contact.php?s=1");
}
else {
header("Location:contact.php?s=2");
}
?>
第2次尝试应该工作,但你必须选择'$ mailheader'用'$ message',作为[文件](http://www.php.net/manual/en/ function.mail.php)指出! – mjb4
我试过这个建议,但是我的结果没有改变。 – lala
我在上面的窗口中添加了代码。 – lala