我一直试图让gmail呈现我发送给它的电子邮件的html内容,但它只是给了我电子邮件的完整文本。当我在comcast.net发送电子邮件给雅虎或我的电子邮件地址时,我看到html电子邮件部分没有任何问题。 Gmail呈现整个事物,包括边界字符串。这是我下面的代码:Gmail将不会使用PHP呈现HTML电子邮件
// Create a boundary string. It must be unique
// so we use the MD5 algorithm to generate a random hash.
$random_hash = md5(date('r', time()));
// Define the headers we want passed. Note that they are separated with \r\n.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: \"" . $replyToName . "\" <" . $replyTo . ">\r\nReply-To: " . $replyTo . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
// Add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-" . $random_hash ."\"";
$headers .= "\r\n";
//This is the plain-text part of the e-mail. This is what the recipient will see if they can only receive text-only e-mails.
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
<?php echo $plainMsg; ?>
<?php echo $mainSite; ?>
______________________________________________________
This e-mail is intended for the eyes of the recipient only. If you are not the
intended recipient, please send an e-mail to <?php echo $replyTo; ?> to inform us of
the mistake, and please destroy any and all copies of this e-mail.
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
<head>
<title>Untitled Document</title>
</head>
<table width="100%" border="0">
<tr>
<td>
<table width="100%" border="0" bgcolor="#ADD8E6">
<tr>
<td><img src="<?php echo $mainLink; ?>/images/BF.gif" width="95" height="65"></td>
<td valign="top"><img src="<?php echo $imageLink; ?>" width="<?php echo $imageWidth; ?>" height="<?php echo $imageHeight; ?>" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<font face="Arial, Helvetica, sans-serif" size="2">
<?php echo $mailMsg; ?>
</font>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<table width="100%" border="0">
<tr>
<td>
<p>
<font face="Arial, Helvetica, sans-serif" size="2">
<a href="<?php echo $mainLink; ?>"><?php echo $mainSite; ?></a>
</font>
<br />
______________________________________________________
<br />
<br />
<font face="Arial, Helvetica, sans-serif" size="1">
This e-mail is intended for the eyes of the recipient only. If you are not the intended recipient, please send an e-mail to <a href="mailto:<?php echo $replyTo; ?>"><?php echo $replyTo; ?></a> to inform us of the mistake, and please destroy any and all copies of this e-mail.
</font>
</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" bgcolor="#ADD8E6">
<tr>
<td align="center">
<font size="-2">All content, images, and data © Bright Futures 2009-2014.
<br />
All rights reserved.</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
--PHP-alt-<?php echo $random_hash; ?> --
当我发送此邮件,我看到的不是编码的全部内容。它显示了消息中的边界字符串和html标记。当我去“显示原始”在Gmail中,我得到如下:
Delivered-To: [email protected]
Received: by 10.182.23.6 with SMTP id i6csp32095obf;
Wed, 19 Feb 2014 01:03:00 -0800 (PST)
X-Received: by 10.68.106.130 with SMTP id gu2mr924626pbb.59.1392800580001;
Wed, 19 Feb 2014 01:03:00 -0800 (PST)
Return-Path: <[email protected]>
Received: from m1plded02-04.prod.mesa1.secureserver.net (m1plded02-04.prod.mesa1.secureserver.net. [64.202.189.17])
by mx.google.com with ESMTP id ri10si3237317pbc.297.2014.02.19.01.02.59
for <[email protected]>;
Wed, 19 Feb 2014 01:02:59 -0800 (PST)
Received-SPF: pass (google.com: domain of [email protected] designates 64.202.189.17 as permitted sender) client-ip=64.202.189.17;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of [email protected] designates 64.202.189.17 as permitted sender) [email protected]
Received: from p3plcpnl0157.prod.phx3.secureserver.net ([184.168.200.188])
by m1plded02-04.prod.mesa1.secureserver.net with : DED :
id U92x1n01E44PGPL0192x1U; Wed, 19 Feb 2014 02:02:59 -0700
Received: from gsg1175 by p3plcpnl0157.prod.phx3.secureserver.net with local (Exim 4.82)
(envelope-from <[email protected]>)
id 1WG33R-001P1W-8P; Wed, 19 Feb 2014 02:02:57 -0700
To: [email protected],[email protected]
Subject: Test E-mail
X-PHP-Script: www.yellowcas.com/sendemail.php for 107.4.20.247
MIME-Version: 1.0
From: "Gregory Greenwell" <[email protected]>
Reply-To: [email protected]
CC: [email protected]
X-Mailer: PHP/5.4.23
Content-Type: multipart/alternative; boundary="PHP-alt-8d0c53f7f76522e3a03197894d7e89fe"
Message-Id: <[email protected]>
Date: Wed, 19 Feb 2014 02:02:57 -0700
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - p3plcpnl0157.prod.phx3.secureserver.net
X-AntiAbuse: Original Domain - gmail.com
X-AntiAbuse: Originator/Caller UID/GID - [267295 956]/[47 12]
X-AntiAbuse: Sender Address Domain - p3plcpnl0157.prod.phx3.secureserver.net
X-Get-Message-Sender-Via: p3plcpnl0157.prod.phx3.secureserver.net: authenticated_id: gsg1175/from_h
X-Source:
X-Source-Args: /usr/sbin/proxyexec -q -d -s /var/run/proxyexec/cagefs.sock/socket /bin/cagefs.server
X-Source-Dir: yellowcas.com:/public_html
--PHP-alt-8d0c53f7f76522e3a03197894d7e89fe
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
We will keep doing this until we get it right!
Why won't this work?
WWW.YELLOWCAS.COM
______________________________________________________
This e-mail is intended for the eyes of the recipient only. If you are not the intended recipient, please send an e-mail to [email protected] to inform us of the mistake, and please destroy any and all copies of this e-mail.
--PHP-alt-8d0c53f7f76522e3a03197894d7e89fe
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
<head>
<title>Untitled Document</title>
</head>
<table width="100%" border="0">
<tr>
<td>
<table width="100%" border="0" bgcolor="#ADD8E6">
<tr>
<td><img src="https://www.yellowcas.com/images/BF.gif" width="95" height="65"></td>
<td valign="top"><img src="https://www.yellowcas.com/images/brightfutures70.gif" width="520" height="60" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<font face="Arial, Helvetica, sans-serif" size="2">
We will keep doing this <b>until we get it right!</b>
Why won't this work?
</font>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<table width="100%" border="0">
<tr>
<td>
<p>
<font face="Arial, Helvetica, sans-serif" size="2">
<a href="https://www.yellowcas.com">WWW.YELLOWCAS.COM</a>
</font>
<br />
______________________________________________________
<br />
<br />
<font face="Arial, Helvetica, sans-serif" size="1">
This e-mail is intended for the eyes of the recipient only. If you are not the intended recipient, please send an e-mail to <a href="mailto:[email protected]">[email protected]</a> to inform us of the mistake, and please destroy any and all copies of this e-mail.
</font>
</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" bgcolor="#ADD8E6">
<tr>
<td align="center">
<font size="-2">All content, images, and data © Bright Futures 2009-2014.
<br />
All rights reserved.
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
--PHP-alt-8d0c53f7f76522e3a03197894d7e89fe--
我很抱歉,这是这么长时间,但我不明白,为什么Gmail是不显示HTML作为HTML。我正在使用php mail()函数发送电子邮件。我看过的每个其他电子邮件客户端都能够很好地呈现html,但gmail只是在电子邮件中显示底层代码。如果任何人有任何想法,我会非常感激听到他们。感谢您抽出时间查看我的代码。
我有这个完全相同的问题。如果您的DNS条目不正确,我发现Gmail添加了X-AntiAbuse。您可以尝试http://www.microsoft.com/mscorp/safety/content/technologies/senderid/wizard/default.aspx为您的DNS条目生成正确的SPF。我正在尝试这个。如果它不起作用,我会为这个问题增加一笔赏金。如果确实有效,我会添加我所做的,作为对您问题的回答。 – miyasudokoro