"From" php 邮件 $headers 未通过
"From" in php mail $headers not passing
我有一个工作正常的邮件脚本,但我无法弄清楚是什么改变没有导致 "from" 通过。
我在邮件功能中有这段代码
$to = ($_POST['email']);
$subject = 'Welcome to the Team!';
$url = 'mydomain.com';
$headers = "From: info@mydomain.com\r\n";
$headers = "BCC: me@mydomain.com\r\n";
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-Type: text/html; charset=ISO-8859-1\r\n";
...
mail($to, $subject, $message, $headers);
问题是,当电子邮件通过时,"from" 看起来像这样:
From: (mydomain)@(someletters&numbers).shr.phx3.(myhost).net
而不是...
From: info@mydomain.com
怎么了?
更新完整代码
...
if(count($errors) == 0) {
$to = 'me@mydomain.com';
$subject = 'Subject';
$headers = "From: me@ mydomain.com\r\n";
$headers = "BCC: someonelese@ mydomain.com\r\n";
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>…Email Message 1…</body></html>";
mail($to, $subject, $message, $headers);
}
if(count($errors) == 0) {
$to = ($_POST['email']);
$subject = 'Subject';
$url = 'mydomain.caom';
$headers = "From: me@ mydomain.com\r\n";
$headers = "BCC: someonelese@ mydomain.com\r\n";
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>…Email Message 2…</body></html>";
mail($to, $subject, $message, $headers);
echo '<META HTTP-EQUIV=Refresh CONTENT="1; URL='.$url.'">';
}
您的 headers 已损坏,需要在第一个声明后使用点连接:
$headers = "From: info@mydomain.com\r\n";
$headers .= "BCC: me@mydomain.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
查阅手册:
编辑:
将您的第二组 headers 重命名为 $headers
,例如:
if(count($errors) == 0) {
$to = 'me@mydomain.com';
$subject = 'Subject';
$headers = "From: me@ mydomain.com\r\n";
$headers .= "BCC: someonelese@ mydomain.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message .= "<html><body>…Email Message 1…</body></html>";
mail($to, $subject, $message, $headers);
}
if(count($errors) == 0) {
$to = ($_POST['email']);
$subject = 'Subject';
$url = 'mydomain.caom';
$headers2 = "From: me@ mydomain.com\r\n";
$headers2 .= "BCC: someonelese@ mydomain.com\r\n";
$headers2 .= "MIME-Version: 1.0\r\n";
$headers2 .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>…Email Message 2…</body></html>";
mail($to, $subject, $message, $headers2);
echo '<META HTTP-EQUIV=Refresh CONTENT="1; URL='.$url.'">';
}
我有一个工作正常的邮件脚本,但我无法弄清楚是什么改变没有导致 "from" 通过。
我在邮件功能中有这段代码
$to = ($_POST['email']);
$subject = 'Welcome to the Team!';
$url = 'mydomain.com';
$headers = "From: info@mydomain.com\r\n";
$headers = "BCC: me@mydomain.com\r\n";
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-Type: text/html; charset=ISO-8859-1\r\n";
...
mail($to, $subject, $message, $headers);
问题是,当电子邮件通过时,"from" 看起来像这样:
From: (mydomain)@(someletters&numbers).shr.phx3.(myhost).net
而不是...
From: info@mydomain.com
怎么了?
更新完整代码
...
if(count($errors) == 0) {
$to = 'me@mydomain.com';
$subject = 'Subject';
$headers = "From: me@ mydomain.com\r\n";
$headers = "BCC: someonelese@ mydomain.com\r\n";
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>…Email Message 1…</body></html>";
mail($to, $subject, $message, $headers);
}
if(count($errors) == 0) {
$to = ($_POST['email']);
$subject = 'Subject';
$url = 'mydomain.caom';
$headers = "From: me@ mydomain.com\r\n";
$headers = "BCC: someonelese@ mydomain.com\r\n";
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>…Email Message 2…</body></html>";
mail($to, $subject, $message, $headers);
echo '<META HTTP-EQUIV=Refresh CONTENT="1; URL='.$url.'">';
}
您的 headers 已损坏,需要在第一个声明后使用点连接:
$headers = "From: info@mydomain.com\r\n";
$headers .= "BCC: me@mydomain.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
查阅手册:
编辑:
将您的第二组 headers 重命名为 $headers
,例如:
if(count($errors) == 0) {
$to = 'me@mydomain.com';
$subject = 'Subject';
$headers = "From: me@ mydomain.com\r\n";
$headers .= "BCC: someonelese@ mydomain.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message .= "<html><body>…Email Message 1…</body></html>";
mail($to, $subject, $message, $headers);
}
if(count($errors) == 0) {
$to = ($_POST['email']);
$subject = 'Subject';
$url = 'mydomain.caom';
$headers2 = "From: me@ mydomain.com\r\n";
$headers2 .= "BCC: someonelese@ mydomain.com\r\n";
$headers2 .= "MIME-Version: 1.0\r\n";
$headers2 .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>…Email Message 2…</body></html>";
mail($to, $subject, $message, $headers2);
echo '<META HTTP-EQUIV=Refresh CONTENT="1; URL='.$url.'">';
}