2012-04-04 54 views
1

我的腳本發送電子郵件,但它不呈現html標記。我不確定爲什麼不。爲什麼不發送發送的郵件的html?

$email = $row['email']; 

$mail_body = '<html> 
<body> 

<p>hello,'.$name.'</p> 
<p>this is a testing email </p> 
<hr /> 
<p>by server</p> 
</body> 
</html>'; 
$subject = "Better website"; 
$to = "$email"; 

$headers = "From: [email protected]\r\n"; 
$headers .= "Content-Type: text/html\r\n"; 

$mail_result = mail($to, $subject, $mail_body, $headers); 

回答

2

嘗試設置MIME類型,以及顯示的手冊中mail()

// 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"; 
+0

我想補充的另一件事是,從未使用aol,hotmail,yahoo,gmail或其他任何知名的郵件頭,因爲godaddy郵件服務器拒絕他們。 – engma 2012-11-03 16:18:16

0

爲Jrod已經回答了你需要添加頁眉

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

,但我發現,這一個是最近搞砸了,不得不將它評論出來:

$headers = 'MIME-Version: 1.0' . "\r\n";