2010-06-18 45 views
44

我使用以下發送電子郵件:換行符在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,沒有任何其他客戶端。

回答

1
<?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); 
?> 
+0

這段代碼如何解決提問者的問題? – APerson 2014-11-28 21:03:35

+0

解釋你的代碼 – 2015-09-10 12:03:28

2

不是一個問題的答案,但可能會有所幫助的人。

發送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));