【发布时间】:2014-02-24 22:47:02
【问题描述】:
我是 php 和 stackoverflow 的新手,我正在尝试找出一个简单的网站联系表。我的表单和电子邮件功能正常,但我有一个难以解决的问题。
发送电子邮件时,发件人电子邮件显示 myusername@p3pxxxxxx.com 这是我的服务器。当我将电子邮件定向到基于域的电子邮件帐户时,他们不会进入我的收件箱,我敢打赌垃圾邮件过滤器正在阻止奇怪的电子邮件地址。所以我尝试将它发送到我的 gmail 收件箱,这很有效,但我不定期查看该电子邮件。我宁愿把它转到我基于域的电子邮件帐户。
所以,我正在寻找一种方法来编辑“发件人”电子邮件地址。而不是用户/服务器,我希望它使用真实的电子邮件地址,我的或发送它的人会更好。这是我目前的一些尝试,但都没有奏效。
几次尝试:
试图提取我的发件人输入的电子邮件地址。
//$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");
}
?>
【问题讨论】:
-
第二次尝试应该可行,但您必须将
$mailheader切换为$message,正如Documentation 指出的那样! -
我尝试了这个建议,但结果没有改变。
-
我在上面的窗口中添加了代码。
-
为正确性编辑了代码。这两个例子现在都做了你想要的吗?
-
感谢您的 cmets 我想通了!