當我從PHP與\ r \ n發送郵件在標題(as it should be according to documentation)從php發送郵件:標題被解釋爲正文?
$headers = "From: $email\r\n";
$headers .= "Reply-To: Just me <$email>\r\n";
$headers .= 'Content-type: text/plain; charset=iso-8859-1' . "\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$subject = "Hello world";
$body = "<html><p>Hey, whats up?</p></html>";
mail($to, $subject, $body, $headers);
一些郵件客戶端會解釋\ r \ n爲在兩個斷行斷行。因此,對於這個郵件()以上真正的郵件內容是這樣的:
X-Message-Delivery: Vj0LEdMMtPAYT0xO0Q9MTtTQ0w9MA==
X-Message-Status: n
Received: from server75.publicompserver.de ([92.43.108.63]) by snt0-mc2-f13.Snt0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675);
Thu, 9 Dec 2010 12:09:22 -0800
Message-ID: <[email protected]>
[lots of other headers]
Date: Thu, 09 Dec 2010 21:09:32 +0100
X-OriginalArrivalTime: 09 Dec 2010 20:09:22.0873 (UTC) FILETIME=[F88C3A90:01CB97DC]
From: $email
Reply-To: Just me <$email>
Content-type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
<html><p>Hey, whats up?</p></html>
現在有些客戶端(Googlemail電子郵件爲例)將忽略這些額外的換行符。其他人(thunderbird)會將第一個額外的換行解釋爲頭部的結尾,並將其餘的頭部行解釋爲身體的一部分(丟失頭部信息,在這種情況下將郵件呈現爲文本而不是html)。
我也看到了其他郵件發送網站的相同問題。
這裏發生了什麼? \ r \ n是根據doc的正確換行符,還是其他地方出錯了? 如何解決?將換行符改爲\ n而不是\ r \ n似乎有所幫助,但由於文檔中提到「你應該使用\ r \ n」,這是不對的,可以嗎?
在你之前的問題中,我提到了'PHP_EOL'常量。你試過這個嗎? – 2010-12-11 07:56:06
由於這些腳本在Apache/Unix上運行,PHP_EOL將是\ n,而不是? – Sam 2010-12-11 07:57:55
也許有人可以清楚地知道unix sendmail腳本如何將'\ n'轉換爲'\ r \ n' – 2010-12-11 08:05:43