换行符在PHP邮件不能正常工作
我使用以下发送电子邮件:换行符在PHP邮件不能正常工作
<php ....
$message = 'Hi '.$fname.', \r\n Your entries for the week of '
.$weekof.' have been reviewed. \r\n Please login and View Weekly reports to see the report and comments. \r\n Thanks, \r\n'.$myname;
mail($to, $subject, $message, $from);
?>
当收到消息时,它不会在“\ r \ n”,但刚开始打印新的一行他们作为消息的一部分。
我只是试图在雷鸟3,没有任何其他客户端。
尝试改变你的'
到"
- PHP解释单引号的文字里面的字符串,而用引号("
),它会扩大\r\n
你想要什么。
的更多信息:http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single
<?php ....
$message = "Hi ".$fname.", \r\n Your entries for the week of "
.$weekof." have been reviewed. \r\n Please login and View Weekly reports to see the report and comments. \r\n Thanks, \r\n".$myname;
mail($to, $subject, $message, $from);
?>
这段代码如何解决提问者的问题? – APerson 2014-11-28 21:03:35
解释你的代码 – 2015-09-10 12:03:28
不是一个问题的答案,但可能会有所帮助的人。
发送HTML消息,而不是\ N,使用<BR>
。
并使用<PRE></PRE>
或CSS预格式化文本,从而将\ n转换为实际的新行。
$headerFields = array(
"From: [email protected]",
"MIME-Version: 1.0",
"Content-Type: text/html;charset=utf-8"
);
mail($to, $subj, $msg, implode("\r\n", $headerFields));
谢谢。这个伎俩。 我不知道单引号和双引号之间有区别。 – ChuckO 2010-06-18 22:19:41
你可以给一个代码示例吗? – 2012-10-04 17:24:26