2011-08-15 208 views
2

我使用這裏找到PHP腳本:PHP的mail()不發送HTML格式的電子郵件正確

http://css-tricks.com/2866-sending-nice-html-email-with-php/

我已經上傳到我的服務器 - 它拒絕正確發送電子郵件!

這是我在Gmail中:(顯示爲原始HTML)

Content-Type: text/html; charset=ISO-8859-1 
<html> 
    <body> 
     <img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" /> 
     <table rules="all" style="border-color: #666;" cellpadding="10"> 
      <tr style='background: #eee;'> 
       <td><strong>Name:</strong> </td> 
       <td>sd</td> 
      </tr> 
      <tr> 
       <td><strong>Email:</strong> </td> 
       <td>[email protected]</td> 
      </tr> 
      <tr> 
       <td><strong>Type of Change:</strong> </td> 
       <td>Change to Existing Content</td> 
      </tr> 
      <tr> 
       <td><strong>Urgency:</strong> </td> 
       <td>Super Wicked Urgent</td> 
      </tr> 
      <tr> 
       <td><strong>URL To Change (main):</strong> </td> 
       <td>http://css-tricks.com/2866-sending-nice-html-email-with-php/</td> 
      </tr> 
      <tr> 
       <td><strong>CURRENT Content:</strong></td> 
       <td>fdasgdsfg</td> 
      </tr> 
      <tr> 
       <td><strong>NEW Content:</strong> </td> 
       <td>sdfgsdgf</td> 
      </tr> 
     </table> 
    </body> 
</html> 

有,我可能不得不更改任何服務器設置???

我也在這臺服務器上使用了一些似乎有同樣問題的wordpress插件。

任何想法都會很棒。

UPDATE:

**更新**

這裏就是我在Gmail中獲得當我點擊 「顯示原始」

Delivered-To: [removed-intentionally]@gmail.com 
Received: by 10.204.157.136 with SMTP id b8cs43947bkx; 
    Sun, 14 Aug 2011 22:29:40 -0700 (PDT) 
Received: from mr.google.com ([10.236.77.232]) 
    by 10.236.77.232 with SMTP id d68mr14702149yhe.74.1313386180151 (num_hops = 1); 
    Sun, 14 Aug 2011 22:29:40 -0700 (PDT) 
Received: by 10.236.77.232 with SMTP id d68mr11051146yhe.74.1313386179570; 
    Sun, 14 Aug 2011 22:29:39 -0700 (PDT) 
Return-Path: <[email protected]> 
Received: from ironport1-mx.cbr1.mail-filtering.com.au (ironport1-mx.cbr1.mail-filtering.com.au [203.88.115.241]) 
    by mx.google.com with ESMTP id g70si16130380yhe.152.2011.08.14.22.29.38; 
    Sun, 14 Aug 2011 22:29:39 -0700 (PDT) 
Received-SPF: neutral (google.com: 203.88.115.241 is neither permitted nor denied by best guess record for domain of [email protected]) client-ip=203.88.115.241; 
Authentication-Results: mx.google.com; spf=neutral (google.com: 203.88.115.241 is neither permitted nor denied by best guess record for domain of [email protected]) [email protected] 
X-IronPort-Anti-Spam-Filtered: true 
X-IronPort-Anti-Spam-Result: AqoHAHOuSE5xFATR/2dsb2JhbABBmHOPCHeEEYd0lCyfAIZHBKQJ 
X-IronPort-AV: E=Sophos;i="4.67,372,1309701600"; 
d="scan'208,217";a="465774510" 
Received: from ub002lps00.cbr.the-server.net.au ([113.20.4.209]) 
by ironport1-mta.cbr1.mail-filtering.com.au with ESMTP; 15 Aug 2011 15:29:03 +1000 
Received: (qmail 14705 invoked by uid 10317); 15 Aug 2011 07:29:02 +0200 
Date: 15 Aug 2011 07:29:02 +0200 
Message-ID: <[email protected]> 
To: [removed-intentionally]@gmail.com 
Subject: Website Change Reqest 
From: [removed-intentionally]@gmail.com 
Reply-To: [removed-intentionally]@gmail.com 
MIME-Version: 1.0 

Content-Type: text/html; charset=ISO-8859-1 

<html><body><img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" /><table rules="all" style="border-color: #666;" cellpadding="10"><tr style='background: #eee;'><td><strong>Name:</strong> </td><td>sd</td></tr><tr><td><strong>Email:</strong> </td><td>[removed-intentionally]@gmail.com</td></tr><tr><td><strong>Type of Change:</strong> </td><td>Change to Existing Content</td></tr><tr><td><strong>Urgency:</strong> </td><td>Super Wicked Urgent</td></tr><tr><td><strong>URL To Change (main):</strong> </td><td>http://css-tricks.com/2866-sending-nice-html-email-with-php/</td></tr><tr><td><strong>CURRENT Content:</strong> </td><td>fdasgdsfg</td></tr><tr><td><strong>NEW Content:</strong> </td><td>sdfgsdgf</td></tr></table></body></html> 
+0

嘗試通過使用SMTP服務器發送電子郵件 – Rikesh

+0

郵政編碼請。你是否修改了該網站的代碼? –

回答

3

有在PHP手冊網站(here)上的一個很好的例子,它展示瞭如何做到這一點。嘗試複製並粘貼示例4.

看起來您並未發送字符串以正確識別標頭中的內容類型。也許你應該在Gmail中做一個「顯示原創」,並在這裏發佈標題,如果你不能從手冊中得到它的話。

+0

(我附上上面的全部輸出) – Simon

2

它看起來像空行MIME-Version指示後的頭一過,所以它輸出Content-Type線作爲普通的文本和HTML的後代替讀該行作爲標題的一部分,要知道轉換剩下的就是HTML。

MIME-Version: 1.0 

Content-Type: text/html; charset=ISO-8859-1 

<html><body> 

嘗試讓無論是生成你的頭,除去MIME-VersionContent-Type之間的空行。 (例如,您是否在該行上有額外的\r\n?您的代碼在生成這些行時的樣子是什麼?)也可以在Content-Type<html>之間添加第二個空白行。

0

包括這在你的郵件標題

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
0

嘗試使用的charset = UTF-8,而不是ISO-8859-1 ...

3

有同樣的問題,其中,發送下面的頭製作的HTML -email一臺服務器上,但另一臺服務器

$headers = 'From: [email protected]\r\n' . 
      'MIME-Version: 1.0' . "\r\n" . 
      'Content-type: text/html; charset=iso-8859-1' . "\r\n" . 
      "X-Mailer: PHP"; 

原來,該\r\n是服務器重複斷行上沒有工作。所以只需\ n作爲換行符爲我工作。

$headers = 'From: [email protected]\n' . 
      'MIME-Version: 1.0' . "\n" . 
      'Content-type: text/html; charset=iso-8859-1' . "\n" . 
      "X-Mailer: PHP";