[英]PHP mail headers not working properly
I am trying to create an email in PHP, but am having a problem constructing the headers. 我正在尝试用PHP创建电子邮件,但是在构造标题时遇到了问题。
I would like the From
to be admin@example.com, and the other headers set as show below. 我希望“
From
为admin@example.com,其他标头设置如下所示。
The problem is that when I send this email, the "from" part in the email client appears as: 问题是,当我发送此电子邮件时,电子邮件客户端中的“发件人”部分显示为:
"admin@example.com rnReply-To: admin@example.com rnMIME-Version: 1.0 rnContent-Type: text/html"
“ admin@example.com rn-答复:admin@example.com rnMIME版本:1.0 rnContent-Type:text / html”
This also inadvertently breaks the rest of the email because it doesn't recognise it as being html. 这也无意间破坏了电子邮件的其余部分,因为它无法识别为html。
// email headers
$headers = 'From: admin@example.com \r\n';
$headers .= 'Reply-To: admin@example.com \r\n';
$headers .= 'MIME-Version: 1.0 \r\n';
$headers .= 'Content-Type: text/html; charset=UTF-8 \r\n';
Any idea on how I can fix these headers? 关于如何解决这些标头的任何想法吗? Thanks.
谢谢。
Change following: 更改以下内容:
$headers = 'From: admin@example.com \r\n';
$headers .= 'Reply-To: admin@example.com \r\n';
$headers .= 'MIME-Version: 1.0 \r\n';
$headers .= 'Content-Type: text/html; charset=UTF-8 \r\n';
To this: 对此:
$headers = "From: admin@example.com \r\n";
$headers .= "Reply-To: admin@example.com \r\n";
$headers .= "MIME-Version: 1.0 \r\n";
$headers .= "Content-Type: text/html; charset=UTF-8 \r\n";
Because \\r\\n
should be in ""
(double quotes). 因为
\\r\\n
应该在""
(双引号)中。
Try: 尝试:
$headers = 'From: admin@example.com' ."\n"; /* note double quote here*/
$headers .= 'Reply-To: admin@example.com' . "\n";/* note double quote here*/
$headers .= 'MIME-Version: 1.0' . "\n";/* note double quote here*/
$headers .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";/* here too*/
edit (can't comment yet) Not sure how much experience you've had with writing scripts for emails but I had to create a system for our newsletter at work, and to come up with good headers that will pass spamblocks, etc, it takes some tinkering. 编辑(尚无法评论)不确定您在编写电子邮件脚本方面有多少经验,但是我必须为工作中的新闻通讯创建一个系统,并想出可以通过垃圾邮件阻止程序的良好标题,等等。需要一些修补。 You might want to look into mail frameworks you can use like Zend.
您可能希望研究可以像Zend一样使用的邮件框架。
Also you try the "\\r\\n" for mime type, its been a while for me but I recall having mixed results with combinations of "\\n, \\r\\n, and \\r\\n\\r\\n" 另外,您尝试使用“ \\ r \\ n”作为哑剧类型,这对我来说已经有一段时间了,但我记得混合使用“ \\ n,\\ r \\ n和\\ r \\ n \\ r \\ n”的结果
原来\\ r \\ n需要双引号,而单引号不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.