2013-11-03 52 views
3

我試圖發送HMTL電子郵件與PHP的mail()功能,並注意到有些事情在電子郵件中被打破。我通過閱讀gmail中的原文發現,郵件正文中的所有行都長度相同,這會在不方便的地方切割HTML標籤。電子郵件添加換行符?

我的標題是html和plain之間的邊界,帶有7位的多部分。什麼我送的一個例子是:

<a href="site.com/unsub">Unsubscribe</a> 

但由於其位置,消息拆分它像

<a href="site.co 
m/ubsub">unsubscribe</a> 

打破了超鏈接。有什麼我失蹤或沒有得到?我已經看到使用像swiftmailer這樣的郵件庫 - 我可以使用它 - 但我想真正理解這種行爲。

編輯:

如何mail()被稱爲:

$headers = 'From: Me <[email protected]>' . "\r\n" . 'MIME-Version: 1.0' 
$headers .= "\r\n" . "Content-Type: multipart/mixed; charset=ISO-8859-1; boundary=$boundary" 
$subject = 'subject'; 
$html_message = '--' . $boundary . "\r\n"; 
$html_message .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n"; 
$html_message .= 'Content-Transfer-Encoding: 7bit' . "\r\n" . "\r\n"; 
$html_message .= $message . "\r\n"; 
// plaintext added similarly, with different content-type. Omitted. 
mail($to,$subject,$html_message, $headers); 

編輯#2:

擴展在$message

$message = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" /><title>" 
$message .= "Page Title</title></head><body style=\"margin: 0; padding: 0; font-family: open \'Open Sans\', \'Open Sans Bold\';\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" ><tr><td><table align=\"center\" bgcolor=\"#FFFFFF\" border=\"0\"cellpadding=\"0\" cellspacing=\"0\" width=\"600\"><tr><td align=\"right\" style=\"padding: 20px 20px 20px 20px;\"> <font color=\"#EA5D0F\">[</font> <a href=\"http://SITE.com\" style=\"color:#000001; text-decoration: none !important;\">Sign In </a><font color=\"#EA5D0F\">][</font> <a href=\"http://about.SITE.com\" style=\"color:#000001; text-decoration: none !important;\">About </a><font color=\"#EA5D0F\">][</font> <a href=\"http:/SITE.com/search\" style=\"color:#000001; text-decoration: none !important;\">Search</a><font color=\"#EA5D0F\">]</font></td></tr><tr><td bgcolor=\"#FFFFFF\" align=\"center\" style=\"padding: 40px 0px 0px 0px;\"><img src=\"http://about.SITE.com/wp-content/uploads/2013/08/SITE.plain_.png\" alt=\"SITE Logo\" width=\"300\" style=\"display: block;\" /></td></tr><tr><td style=\"padding: 10px 20px 20px 20px;\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" ><tr><td bgcolor=\"#FFFFFF\" style=\"padding: 30px 10px 10px 10px; text-align:center; font-size: 1.2em; font-weight:bold;\"> <hr color=\"#EA5D0F\"/>" 

這持續了很長一段時間。不知道要包含多少。

+0

你使用這些郵件(如小枝)一些模板系統:雖然我不知道原因是什麼,它被替換每個>通過>\r\n解決了嗎? – puelo

+0

你確定你不是以某種方式在你的代碼中保存額外的換行符(例如,來自某種文本換行)嗎? – Fluffeh

+2

你能告訴我們你怎麼做'mail()'調用? –

回答

0

我以前確實有這個問題。

$message = str_replace(">", ">\r\n", $message);