2011-04-19 70 views
7

嗨, 嘗試通過郵件()發送HTML郵件,但是Gmail中只顯示電子郵件作爲純文本,無標記,如HTML格式的郵件:如何發送使用PHP

mail("[email protected]", "subject", "<i>Italic Text</i>"); 

只是顯示爲

<i>Italic Text</i> 

任何想法?

+0

可能的重複[在PHP發送的電子郵件中使用HTML格式](http://stackoverflow.com/questions/4971322/use-html-formatting-in-email-sent-from-php) – mario 2011-04-19 11:09:49

+0

可能的重複[ Php mail:如何發送html?](http://stackoverflow.com/questions/4897215/php-mail-how-to-send-html) – mario 2011-04-19 11:10:37

+0

[Include html in email](http:// stackoverflow .com/questions/4916477/include-html-in-email) – mario 2011-04-19 11:11:09

回答

15

您必須指定郵件的內容是HTML:

mail("[email protected]", "subject", "<i>Italic Text</i>", "Content-type: text/html; charset=iso-8859-1"); 
3

你需要有一個正確的HTML文檔:

$msg = "<html><head></head><body><i>Italic Text</i></body></html>"; 

編輯:

和發送標題:

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

mail("[email protected]", $msg, $headers); 
1

爲了使其得到適當的解釋,還必須設置的標頭中的電子郵件,尤其是:

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

你還應該設置其他常規頭。該消息最終可以如下發送:

mail($to, $subject, $message, $headers); 

有關更多信息,請參閱php manual mail page