Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP邮件头无法正常工作_Php_Email - Fatal编程技术网

PHP邮件头无法正常工作

PHP邮件头无法正常工作,php,email,Php,Email,我试图用PHP创建一封电子邮件,但在构建邮件头时遇到了问题 我希望中的是admin@example.com,以及其他标题集,如下所示 问题是,当我发送此电子邮件时,电子邮件客户端中的“发件人”部分显示为: "admin@example.com答复:admin@example.comrnMIME版本:1.0 RN内容类型:文本/html“ 这也无意中破坏了电子邮件的其余部分,因为它无法将其识别为html // email headers $headers = 'From: admin@exampl

我试图用PHP创建一封电子邮件,但在构建邮件头时遇到了问题

我希望中的
是admin@example.com,以及其他标题集,如下所示

问题是,当我发送此电子邮件时,电子邮件客户端中的“发件人”部分显示为:

"admin@example.com答复:admin@example.comrnMIME版本:1.0 RN内容类型:文本/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';

知道如何修复这些标题吗?谢谢。

结果是\r\n需要双引号,单引号不起作用。

更改如下:

$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';
为此:

$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";
因为
\r\n
应该在
中(双引号)。

请尝试:

$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*/
编辑(还不能评论) 我不知道你在为电子邮件编写脚本方面有多少经验,但我必须为我们的工作时事通讯创建一个系统,并且想出好的标题来传递垃圾邮件等等,这需要一些修补。 您可能希望研究可以像Zend一样使用的邮件框架


您还尝试了mime类型的“\r\n”,这对我来说已经有一段时间了,但我记得使用“\n、\r\n和\r\n\r\n”的组合会产生混合的结果,这些组合只能用双引号解析。不需要尾随空格。