换行符不能在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”处开始新行,而只是将它们作为消息的一部分进行打印。
我只在Thunderbird 3上试过,没有其他的客户端。
尝试改变你的'
到"
– PHP将单引号内的string解释为文字,而用引号( "
)将\r\n
扩展到你想要的。
更多信息: http : //www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single
不是问题的答案,但可能对某人有帮助。
发送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));
<?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); ?>