新行 ( ) 在电子邮件正文中不起作用 [英] New lines ( ) are not working in email body
问题描述
我正在使用 PHP mail()
函数:
I am using PHP mail()
function:
$to = 'AAAA <postmaster@xxx.xx>';
$subject = 'BBBB';
$message = "CCCC
CCCC CCCC
CCC
CCC
CCC
CCCC";
$headers = 'From: DDD<postmaster@xxx.xx>' . "
";
$headers .= "Content-Type: text/html; charset="UTF-8"; format=flowed
";
$headers .= "Mime-Version: 1.0
";
$headers .= "Content-Transfer-Encoding: quoted-printable
";
mail($to, $subject, $message, $headers);
当我收到这封电子邮件时,它看起来像这样:
When I receive this email it looks like this:
CCCC CCCC CCCC CCC CCC CCC CCCC
我希望是这样的:
CCCC
CCCC CCCC CCC
CCC
CCC
CCCC
它在没有 Content-Type
HTTP 标头.如何创建换行并仍然使用我的Content-Type"声明?
It works fine without Content-Type
HTTP header. How can I make new lines and still use my "Content-Type" declaration?
推荐答案
你需要使用
因为你的 Content-Type
是 text/html
.
You need to use a <br>
because your Content-Type
is text/html
.
它可以在没有 Content-Type
标头的情况下工作,因为这样您的电子邮件将被解释为 纯文本.如果你真的想使用
你应该使用 Content-Type: text/plain
但那样你会丢失任何标记.
It works without the Content-Type
header because then your e-mail will be interpreted as plain text. If you really want to use
you should use Content-Type: text/plain
but then you'll lose any markup.
另请在此处查看类似问题.
这篇关于新行 ( ) 在电子邮件正文中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!