因此,我为我的网站设置了联系表单,当人们注册时,它会向我发送电子邮件。这是代码:
<?php
include("include/settings.php");
if(isset($_POST['name']) && isset($_POST['contactEmail']) && isset($_POST['message'])){
$name = $_POST['name'];
$from = $_POST['contactEmail'];
$message = $_POST['message'];
$subject = "Message from " . $name;
if (mail ($to, $subject, $message, $from)) {
$response = array('sent' => 1);
echo json_encode($response);
} else {
$response = array('sent' => 0);
echo json_encode($response);
}
}
?>
现在,当我收到一封电子邮件时,它来自我的高迪服务器名称。我不介意它是否继续从此电子邮件发送,但我需要将from名称更改为其他名称。这可能吗?
您当前的标头被解释为
[email protected], Message from John, the messsage, [email protected]
应解释为
[email protected], Message from John, the messsage, From: [email protected]
因此,邮局局长说:“这里没有发件人:因此,我假设您的意思是“我的服务器”。
使用适当的标题:http://php.net/manual/en/function.mail.php
$headers = "From: ". $name . " <" . $from . ">\r\n";
然后将您的礼物改写mail()
为:
mail ($to, $subject, $message, $headers)
如果您希望它有所不同,请使用其他不同的电子邮件地址。
注意: Mail希望“发件人”是电子邮件地址,而不是人的名字。
因此,您可以执行以下操作:
$from_other = "[email protected]";
然后做:
$headers = "From: ". $name . " <" . $from_other . ">\r\n";
然后将您的礼物重写mail()
为:
mail ($to, $subject, $message, $headers)
您还可以使用其他标题选项:
$from = $from . ' <' . $from . '>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Reply-To: ' . $from . "\r\n";
$headers .= 'Return-Path: ' . $from . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
$headers .= 'X-Originating-IP: ' . $_SERVER['SERVER_ADDR'] . "\r\n";
Reply-To:
,如果你想使用一个不同的“回复”。可以将这些变量更改为您希望的任何变量。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句