2016-06-20 63 views
1

當我試圖通過PHP發送我的郵件,GMail不接受我的html用PHP發送電子郵件時,Gmail不起作用

簡單的例子:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
</head> 

<body style="padding:0px; margin:0PX;" bgcolor="#dfdfdf"> 
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="" style="table-layout:fixed; margin:0 auto;"> 
<tr> 
<td width="640" align="center" valign="top"> 

    Screenshot: <img src="data:image/jpeg;base64,someimginfo" /> 

</td> 
</tr> 
</table> 
</body> 
</html> 

GMail的輸出:

enter image description here

Gmail編輯我的文本例如<html> - >"<html>"

我使用的標題:MIME-Version: 1.0 & Content-type: text/html; charset=UTF-8

我在做什麼錯?

編輯PHP代碼:

<?php 
$recipient = "[email protected]"; 

$image = $_POST["image"]; 
$contact = $_POST["contact"]; 
$token = $_POST["token"]; 

if($token != "***"){ 
    exit('{"success":false, "error":"Invalid Token"}'); 
} 

$from = (filter_var($contact, FILTER_VALIDATE_EMAIL)) ? $contact : 'no- [email protected]'; 
$header = 'From: [email protected]' . "\r\n"; 
$headers .= 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; 

$txt = ' 
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
</head> 

<body style="padding:0px; margin:0PX;" bgcolor="#dfdfdf"> 
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="" style="table-layout:fixed; margin:0 auto;"> 
<tr> 
<td width="640" align="center" valign="top"> 

    Screenshot: <img src="data:image/jpeg;base64,' . $image . '" /> 

</td> 
</tr> 
</table> 
</body> 
</html> 
'; 

if(mail($recipient, "APP Support request", $txt, $header)){ 
    exit('{"success":true}'); 
} 

exit('{"success":false, "image":"' . $image . '"}'); 
?> 
+0

您可以發佈您用來設置這些標題併發送電子郵件的PHP代碼嗎? –

+0

@ RoryO'Kane完成 –

回答

1

它看起來像這個問題是在這些行:

$header = 'From: [email protected]' . "\r\n"; 
$headers .= 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; 

// … 

if(mail($recipient, "APP Support request", $txt, $header)){ 

你的名字$header$headers之間切換。因此,當您將text/html內容類型添加到變量$headers時,這不會影響用於實際發送電子郵件的$header變量。

您應該將所有這些變量切換爲相同名稱$headers