换行不在PHP邮件中工作

时间:2010-06-18 22:13:32

标签: php email

我正在使用以下内容发送电子邮件:

<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”处开始新行,而只是将其作为邮件的一部分打印出来。

我只在Thunderbird 3中尝试过,而不是任何其他客户端。

3 个答案:

答案 0 :(得分:106)

尝试将'更改为" - php将单引号内的字符串解释为文字,而使用引号(")则会将\r\n扩展为你想要的。

更多信息:http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single

答案 1 :(得分:4)

不是问题的答案,但可能对某人有帮助。

发送HTML消息,而不是\ n,使用<BR>

使用<PRE></PRE>或CSS作为预先格式化的文本,从而将\ n转换为实际的新行。

$headerFields = array(
    "From: who@are.you",
    "MIME-Version: 1.0",
    "Content-Type: text/html;charset=utf-8"
    );
mail($to, $subj, $msg, implode("\r\n", $headerFields));

答案 2 :(得分:3)

<?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);
?>