[英]PHP mail header problems
我目前有两个问题:
在我的Gmail,发件人:头不尊重'我的联系表格的名字。 它默认为其他东西。
当我收到gmail电子邮件时,它当然是从myemail@mydomain.com
发送的(以避免垃圾邮件文件夹),但是当我单击“回复”时,我希望它使用联系表单用户的$ email,而不是myemail@mydomain.com
我确定我缺少一些细节,所以如果我错过了一些事情,请告诉我,我将添加它。
这是我的代码:
if (!isset($_REQUEST['name']) || !isset($_REQUEST['email']) || !isset($_REQUEST['message'])) {
die();
}
// PHP parameters
$to = "myemail@gmail.com";
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
// Subject
$email_subject = $_POST['name'] . ' ' . 'is contacting you from mywebsite.com' . '!';
// body of email
$body = ""
$body = wordwrap($body, 60, "\n");
// Headers
$headers .= "From: My contact form <myemail@mydomain.com>" . "\r\n";
$headers .= "Reply-To: $email" . "\r\n";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "Return-Path: myemail@mydomain.com" . "\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
// Mail it
mail( $to, $email_subject, $body, $headers, "-fmyemail@mydomain.com" );
在该行中缺少连接符号( .
),这导致$headers
丢失值From
和Reply-To
因为它们在重新初始化$header
的行之前设置。
在您的代码中,重新初始化$headers
是:
$headers = "MIME-Version: 1.0" . "\r\n";
它应该更改为:
$headers = "From: My contact form <myemail@mydomain.com>" . "\r\n";
$headers .= "Reply-To: $email" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "Return-Path: myemail@mydomain.com" . "\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
对于第1部分, =
设置变量,然后.=
添加到变量。 因此,您将覆盖先前声明的变量。 它应显示为:
$headers = "From: My contact form <myemail@mydomain.com>" . "\r\n";
$headers .= "Reply-To: $email" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "Return-Path: myemail@mydomain.com" . "\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
对于第2部分,请尝试以下操作: php联系人表格中的回复地址
换句话说,改变
$headers .= "Reply-To: $email" . "\r\n";
至
$headers .= "Reply-To: " . $email . "\r\n";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.