2016-06-20 67 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