2015-12-30 36 views
0
$mail_body = '<html> 
<body style="background-color:#CCC; color:#000; font-family: Arial, Helvetica, sans-serif; line-height:1.8em;"> 
<h3><a href="http://www.grillontherock.com"><img src="http://i.imgur.com/OODKT9h.png" alt="GR" width="194" height="123" border="0"></a> 
</h3> 
<p>Hello ' . $name . ',</p> 
<p>You can make this out to be just like most any web page or design format you require using HTML and CSS.</p> 
<p>Grill on the Rock </p> 
<hr> 
<p>To opt out of receiving this newsletter, <a href="http://grillontherock.x10host.com/email/optout.php?e=' . $email . '">click here</a> and we will remove you from the listing immediately.</p> 
</body> 
</html>'; 

     $to = "$email"; 
     $subject = "Example Grill on the Rock Email"; 
     $from="[email protected]"; 

     $mail_result = mail($to, $subject, $mail_body, "From:".$from); 

    } 
    if($mail_result){ 
     echo "Email has been sent successfully"; 
    } 

我有用php和html發送郵件的問題。php的郵件語法錯誤

此代碼工作完全正常,但我收到的電子郵件是

enter image description here

但是當我使用的HTML文件PHP代碼灰色雙引號因故。

$mail_body = "<html> 
<body style="background-color:#CCC; color:#000; font-family: Arial, Helvetica, sans-serif; line-height:1.8em;"> 
<h3><a href="http://www.grillontherock.com"><img src="http://i.imgur.com/OODKT9h.png" alt="GR" width="194" height="123" border="0"></a> 
</h3> 
<p>Hello ' . $name . ',</p> 
<p>You can make this out to be just like most any web page or design format you require using HTML and CSS.</p> 
<p>Grill on the Rock </p> 
<hr> 
<p>To opt out of receiving this newsletter, <a href="http://grillontherock.x10host.com/email/optout.php?e=' . $email . '">click here</a> and we will remove you from the listing immediately.</p> 
</body> 
</html>"; 

     $to = "$email"; 
     $subject = "Example Grill on the Rock Email"; 
     $from="[email protected]"; 

     $mail_result = mail($to, $subject, $mail_body, "From:".$from); 

    } 
    if($mail_result){ 
     echo "Email has been sent successfully"; 
    } 

有點新的PHP和HTML,我目前找不到類似的問題。

此外,是否有可能將電子郵件作爲HTML表單,並通過發送PHP文件將該HTML?

+1

丹尼不是附加截圖,添加相關的代碼片段。他們會對社區更有幫助,以幫助您。 – NSNoob

+0

刪除代碼圖片。請使用輸入的代碼來尋求幫助。 –

+0

把你的代碼,而不是屏幕截圖丹尼..如果有人想幫他,他可以至少嘗試複製你的代碼..... – rahul

回答

1

您需要設置Content-Typetext/html在郵件頭

例頭與Content Type

$headers = "From: [email protected]\r\n"; 
$headers .= "Reply-To: [email protected]\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

然後

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

@edit。

還要檢查的exaple#4於: http://php.net/manual/en/function.mail.php

+0

非常感謝幫助額外的鏈接幫助了很多 –

+0

不客氣。我很高興能夠提供幫助。 – RysQ

0

您需要設置Content-Typetext/html在郵件標題發送郵件HTML郵件。

例標題:

$headers = "From: [email protected]\r\n"; 
$headers .= "Reply-To: [email protected]\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

最後你的內容後,您需要發送郵件如下所示。

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

然後,對於你的雙引號問題:在這裏你用雙引號內雙引號。如果是這樣,那麼你需要用「/」來轉義它。