2013-03-09 123 views
1

不顯示我用下面的代碼來發送電子郵件:HTML郵件客戶端Outlook Express中

 $to = "****.co.uk"; 
     $subject = "Membership submission"; 
     $body = ""; 

     $date = date('d/m/Y H:i:s'); 

     $body .= "<b>REF</b>: " . $postId . "<br />"; 
     $body .= "<b>On</b>: " . $date . "<br />"; 
     $body .= "<b>First name</b>: " . $postFirstName . "<br />"; 
     $body .= "<b>Last name</b>: " . $postLastName . "<br />"; 
     $body .= "<b>Company name</b>: " . $postCompanyName . "<br />"; 
     $body .= "<b>Address</b>:<br /> " . nl2br($postAddress) . "<br />"; 
     $body .= "<b>Telephone number</b>: " . $postTelephoneNumber . "<br />";   
     $body .= "<b>Email</b>: " . $postEmail . "<br />";  
     $body .= "<b>Website</b>: " . $postWebsite . "<br />";   
     $body .= "<b>Skills</b>:<br /> " . nl2br($postSkills) . "<br />";  
     $body .= "<b>Payment method</b>: " . $postPaying . "<br />";  

     // To send HTML mail, the Content-type header must be set 
     $headers = 'MIME-Version: 1.0' . "\r\n"; 
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

     // Additional headers 
     $headers .= 'From: [email protected]*****.co.uk' . "\r\n"; 

     if (mail($to, $subject, $body, $headers)) { 
     // 

在outlook.com和Windows談到通過罰款8郵件程序。 但是,當發送到我的客戶端的桌面Outlook程序涉及通過這樣的:

Content-type: text/html; charset=iso-8859-1 

From: [email protected]*** 
X-Brightmail-Tracker: AAAAAQAAAlk= 

<b>REF</b>: 513a8440922ea<br /><b>On</b>: 09/03/2013 00:40:59<br /><b>First 
name</b>: a name<br /><b>Last name</b>: a last name<br /><b>Company name</b>: My 
Company name<br /><b>Address</b>:<br /> an address,<br /> 

2,<br /> 

3,<br /> 

4,<br /> 

postcode<br /><b>Telephone number</b>: 521213091<br /><b>Email</b>: 
****.co.uk<br /><b>Website</b>: site.com<br 
/><b>Skills</b>:<br /> I do not have any skills to assist with.<br /> 

<br /> 

Sorry<br /><b>Payment method</b>: Bank transfer<br /> 

有什麼不對我的代碼?

我只是嘗試添加此:

Content-Type: text/plain; charset=us-ascii 
Content-Transfer-Encoding: 7bit 

現在我收到outlook.com的電子郵件是唯一的HTML。這樣就殺了它?啊,這裏有什麼問題!

+0

可能重複(http://stackoverflow.com/questions/3058897/sending-html-email-from-php) – j0k 2013-03-09 11:33:01

回答

0

看來你缺少MIME規格:補充一點:

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

它也顯示在PHP-Documentation for the mail-function

+0

原來的職位狀態的MIME-版本?它已經在那裏了? – Jimmyt1988 2013-03-09 11:38:27

+0

@JamesT你的輸出不包含MIME標記 – Vineet1982 2013-03-09 11:41:47

+0

因此,而不是將它添加到$頭部分,我應該將它添加到$ body?它已經宣佈爲標題,你可以看到上面 – Jimmyt1988 2013-03-09 11:43:14

0

我不確定,但這可能是因爲您錯過了開頭<html>並關閉</html>標籤。

郵件()函數的example in the documentation可能會有所幫助。

+0

Right,ill試試看:D謝謝 – Jimmyt1988 2013-03-09 11:51:11

+0

@JamesT:有用嗎? – 2013-03-09 18:08:52

+0

不,它沒有......我想我添加了一個標題,但它似乎在那之後工作?但我只是不相信..所以不知道答案是什麼,但它不是HTML。 – Jimmyt1988 2013-03-12 01:50:00

0

這是我正在使用的代碼片段。我工作得很好。 [從PHP發送HTML郵件]的

// Boundary 
$innerboundary ="=_".time()."_="; 

// Mail-Header 
$header ="MIME-Version: 1.0\n"; 
$header.="From: [email protected]\n"; 
$header.="Reply-To: [email protected]\n"; 
$header.="X-Mailer: kmPHP-Mailer\n"; 
$header.="Content-Type: multipart/alternative;\n\tboundary=\"".$innerboundary."\"\n"; 

// Mail-subject 
$subject ="Subject goes here"; 
$body =""; 

// HTML part 
$body.="\n--".$innerboundary."\n"; 
$body.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n"; 
$body.="Content-Transfer-Encoding: base64\n\n"; 
$body.=chunk_split(base64_encode(($html_string_goes_here)))."\n\n"; 
$body.="\n--".$innerboundary."--\n"; 
$body.="\n\n"; 
+0

感謝您的幫助,但這似乎在電子郵件中輸出無稽之談 – Jimmyt1988 2013-03-09 17:24:02