php mailheaders vs网站上的标题电子邮件来自

时间:2014-02-24 22:47:03

标签: php forms email contact

我是php和stackoverflow的新手,我正在尝试找出一个简单的网站联系表单。我的表单和电子邮件运行正常,但我有一个令人难以理解的唠叨问题。

发送电子邮件时,发件人电子邮件中写着myusername@p3pxxxxxx.com,这是我的服务器。当我将电子邮件定向到我的基于域的电子邮件帐户时,他们没有进入我的收件箱,我打赌垃圾邮件过滤器正在停止奇怪的电子邮件地址。所以我尝试将它发送到我的Gmail收件箱,该收件箱有效,但我没有定期查看该电子邮件。我宁愿把它带到我的基于域的电子邮件帐户。

所以,我正在寻找一种编辑'from'电子邮件地址的方法。我希望它使用真实的电子邮件地址而不是用户/服务器,我或发送它的人会更好。以下是一些尝试以及我目前所拥有的一些尝试,但都没有。

几次尝试:

尝试拉出输入发件人的电子邮件地址。

//$mailheader = "From: ".$_POST["email"]."\r\n"; 
//$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";

这是另一次尝试。

//$mailheaders = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";

我现在有什么:

<?
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$security = $_POST['security'];

$to = "myemailaddress@gmail.com";
$subject = "Contact Message from Website";
$mailheaders = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
$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 = "mail@example.com";
$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: webmaster@example.com\r\nReply-To: website@example.com";

if ($security=="10") {
    mail($to,$subject,$message,$mailheaders);
    header("Location:contact.php?s=1");
}
else {
    header("Location:contact.php?s=2");
}
?>

1 个答案:

答案 0 :(得分:0)

阿拉斯泰尔的纠正应该有效。

当您调用mail函数时,您没有以正确的顺序传递变量。

你如何称呼它: mail($to, $subject, $mailheaders, $message)

但实际订单是: mail($to, $subject, $message, $mailheaders)

请注意我如何切换$ message和$ mailheaders

您可以查看PHP的文档,例如:

http://us3.php.net/manual/en/function.mail.php

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )