我正在使用 PHP mail()
函数:
$to = 'AAAA <postmaster@xxx.xx>';
$subject = 'BBBB';
$message = "CCCC\r\nCCCC CCCC \r CCC \n CCC \r\n CCC \n\r CCCC";
$headers = 'From: DDD<postmaster@xxx.xx>' . "\r\n";
$headers .= "Content-Type: text/html; charset=\"UTF-8\"; format=flowed \r\n";
$headers .= "Mime-Version: 1.0 \r\n";
$headers .= "Content-Transfer-Encoding: quoted-printable \r\n";
mail($to, $subject, $message, $headers);
当我收到这封电子邮件时,它看起来是这样的:
CCCC CCCC CCCC CCC CCC CCC CCCC
我希望是这样的:
CCCC
CCCC CCCC CCC
CCC
CCC
CCCC
没有 Content-Type
也能正常工作HTTP header 。如何制作新行并仍然使用我的“Content-Type”声明?
最佳答案
您需要使用 <br>
因为你的Content-Type
是 text/html
.
它可以在没有 Content-Type
的情况下工作 header ,因为这样您的电子邮件将被解释为 纯文本。如果你真的想用\n
你应该使用 Content-Type: text/plain
但是你会丢失任何标记。
还可以查看类似问题 here .
关于php - 新行 (\r\n) 在电子邮件正文中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16063312/