php mail() 未正确发送 HTML 电子邮件
我正在使用在这里找到的 php 脚本:
http:// css-tricks.com/2866-sending-nice-html-email-with-php/
我已将其上传到我的服务器 - 但它拒绝正确发送电子邮件!
这是我在 Gmail 中收到的内容:(显示为原始 html)
Content-Type: text/html; charset=ISO-8859-1
<html>
<body>
<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />
<table rules="all" style="border-color: #666;" cellpadding="10">
<tr style='background: #eee;'>
<td><strong>Name:</strong> </td>
<td>sd</td>
</tr>
<tr>
<td><strong>Email:</strong> </td>
<td>[email protected]</td>
</tr>
<tr>
<td><strong>Type of Change:</strong> </td>
<td>Change to Existing Content</td>
</tr>
<tr>
<td><strong>Urgency:</strong> </td>
<td>Super Wicked Urgent</td>
</tr>
<tr>
<td><strong>URL To Change (main):</strong> </td>
<td>http://css-tricks.com/2866-sending-nice-html-email-with-php/</td>
</tr>
<tr>
<td><strong>CURRENT Content:</strong></td>
<td>fdasgdsfg</td>
</tr>
<tr>
<td><strong>NEW Content:</strong> </td>
<td>sdfgsdgf</td>
</tr>
</table>
</body>
</html>
是否有任何我可能需要更改的服务器设置???
我还在该服务器上使用了一些似乎有相同问题的 WordPress 插件。
任何想法都会很棒。
更新:
- 代码仅在所有需要的地方用我的真实电子邮件进行了编辑。 (为了安全起见,在此处删除) - 完整代码可见:http: //css-tricks.com/2866-sending-nice-html-email-with-php/
** 更新 **
这是我点击“显示原始内容”时在 Gmail 中得到的内容
Delivered-To: [removed-intentionally]@gmail.com
Received: by 10.204.157.136 with SMTP id b8cs43947bkx;
Sun, 14 Aug 2011 22:29:40 -0700 (PDT)
Received: from mr.google.com ([10.236.77.232])
by 10.236.77.232 with SMTP id d68mr14702149yhe.74.1313386180151 (num_hops = 1);
Sun, 14 Aug 2011 22:29:40 -0700 (PDT)
Received: by 10.236.77.232 with SMTP id d68mr11051146yhe.74.1313386179570;
Sun, 14 Aug 2011 22:29:39 -0700 (PDT)
Return-Path: <[email protected]>
Received: from ironport1-mx.cbr1.mail-filtering.com.au (ironport1-mx.cbr1.mail-filtering.com.au [203.88.115.241])
by mx.google.com with ESMTP id g70si16130380yhe.152.2011.08.14.22.29.38;
Sun, 14 Aug 2011 22:29:39 -0700 (PDT)
Received-SPF: neutral (google.com: 203.88.115.241 is neither permitted nor denied by best guess record for domain of [email protected]) client-ip=203.88.115.241;
Authentication-Results: mx.google.com; spf=neutral (google.com: 203.88.115.241 is neither permitted nor denied by best guess record for domain of [email protected]) [email protected]
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: AqoHAHOuSE5xFATR/2dsb2JhbABBmHOPCHeEEYd0lCyfAIZHBKQJ
X-IronPort-AV: E=Sophos;i="4.67,372,1309701600";
d="scan'208,217";a="465774510"
Received: from ub002lps00.cbr.the-server.net.au ([113.20.4.209])
by ironport1-mta.cbr1.mail-filtering.com.au with ESMTP; 15 Aug 2011 15:29:03 +1000
Received: (qmail 14705 invoked by uid 10317); 15 Aug 2011 07:29:02 +0200
Date: 15 Aug 2011 07:29:02 +0200
Message-ID: <[email protected]>
To: [removed-intentionally]@gmail.com
Subject: Website Change Reqest
From: [removed-intentionally]@gmail.com
Reply-To: [removed-intentionally]@gmail.com
MIME-Version: 1.0
Content-Type: text/html; charset=ISO-8859-1
<html><body><img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" /><table rules="all" style="border-color: #666;" cellpadding="10"><tr style='background: #eee;'><td><strong>Name:</strong> </td><td>sd</td></tr><tr><td><strong>Email:</strong> </td><td>[removed-intentionally]@gmail.com</td></tr><tr><td><strong>Type of Change:</strong> </td><td>Change to Existing Content</td></tr><tr><td><strong>Urgency:</strong> </td><td>Super Wicked Urgent</td></tr><tr><td><strong>URL To Change (main):</strong> </td><td>http://css-tricks.com/2866-sending-nice-html-email-with-php/</td></tr><tr><td><strong>CURRENT Content:</strong> </td><td>fdasgdsfg</td></tr><tr><td><strong>NEW Content:</strong> </td><td>sdfgsdgf</td></tr></table></body></html>
I'm using the php script found here:
http://css-tricks.com/2866-sending-nice-html-email-with-php/
I've uploaded it to my server - and it refuses to send emails correctly!
This is what I receive in Gmail: (displays as raw html)
Content-Type: text/html; charset=ISO-8859-1
<html>
<body>
<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />
<table rules="all" style="border-color: #666;" cellpadding="10">
<tr style='background: #eee;'>
<td><strong>Name:</strong> </td>
<td>sd</td>
</tr>
<tr>
<td><strong>Email:</strong> </td>
<td>[email protected]</td>
</tr>
<tr>
<td><strong>Type of Change:</strong> </td>
<td>Change to Existing Content</td>
</tr>
<tr>
<td><strong>Urgency:</strong> </td>
<td>Super Wicked Urgent</td>
</tr>
<tr>
<td><strong>URL To Change (main):</strong> </td>
<td>http://css-tricks.com/2866-sending-nice-html-email-with-php/</td>
</tr>
<tr>
<td><strong>CURRENT Content:</strong></td>
<td>fdasgdsfg</td>
</tr>
<tr>
<td><strong>NEW Content:</strong> </td>
<td>sdfgsdgf</td>
</tr>
</table>
</body>
</html>
Is there any server settings that I may have to change???
I've also used some wordpress plugins on this server that seem to have the same issue.
Any ideas would be great.
UPDATE:
- Code has only been edited with my real email in all places that required it. (removed here for security) - full code visible here: http://css-tricks.com/2866-sending-nice-html-email-with-php/
** UPDATE **
Here's what i get in Gmail when i click "Show Original"
Delivered-To: [removed-intentionally]@gmail.com
Received: by 10.204.157.136 with SMTP id b8cs43947bkx;
Sun, 14 Aug 2011 22:29:40 -0700 (PDT)
Received: from mr.google.com ([10.236.77.232])
by 10.236.77.232 with SMTP id d68mr14702149yhe.74.1313386180151 (num_hops = 1);
Sun, 14 Aug 2011 22:29:40 -0700 (PDT)
Received: by 10.236.77.232 with SMTP id d68mr11051146yhe.74.1313386179570;
Sun, 14 Aug 2011 22:29:39 -0700 (PDT)
Return-Path: <[email protected]>
Received: from ironport1-mx.cbr1.mail-filtering.com.au (ironport1-mx.cbr1.mail-filtering.com.au [203.88.115.241])
by mx.google.com with ESMTP id g70si16130380yhe.152.2011.08.14.22.29.38;
Sun, 14 Aug 2011 22:29:39 -0700 (PDT)
Received-SPF: neutral (google.com: 203.88.115.241 is neither permitted nor denied by best guess record for domain of [email protected]) client-ip=203.88.115.241;
Authentication-Results: mx.google.com; spf=neutral (google.com: 203.88.115.241 is neither permitted nor denied by best guess record for domain of [email protected]) [email protected]
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: AqoHAHOuSE5xFATR/2dsb2JhbABBmHOPCHeEEYd0lCyfAIZHBKQJ
X-IronPort-AV: E=Sophos;i="4.67,372,1309701600";
d="scan'208,217";a="465774510"
Received: from ub002lps00.cbr.the-server.net.au ([113.20.4.209])
by ironport1-mta.cbr1.mail-filtering.com.au with ESMTP; 15 Aug 2011 15:29:03 +1000
Received: (qmail 14705 invoked by uid 10317); 15 Aug 2011 07:29:02 +0200
Date: 15 Aug 2011 07:29:02 +0200
Message-ID: <[email protected]>
To: [removed-intentionally]@gmail.com
Subject: Website Change Reqest
From: [removed-intentionally]@gmail.com
Reply-To: [removed-intentionally]@gmail.com
MIME-Version: 1.0
Content-Type: text/html; charset=ISO-8859-1
<html><body><img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" /><table rules="all" style="border-color: #666;" cellpadding="10"><tr style='background: #eee;'><td><strong>Name:</strong> </td><td>sd</td></tr><tr><td><strong>Email:</strong> </td><td>[removed-intentionally]@gmail.com</td></tr><tr><td><strong>Type of Change:</strong> </td><td>Change to Existing Content</td></tr><tr><td><strong>Urgency:</strong> </td><td>Super Wicked Urgent</td></tr><tr><td><strong>URL To Change (main):</strong> </td><td>http://css-tricks.com/2866-sending-nice-html-email-with-php/</td></tr><tr><td><strong>CURRENT Content:</strong> </td><td>fdasgdsfg</td></tr><tr><td><strong>NEW Content:</strong> </td><td>sdfgsdgf</td></tr></table></body></html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
遇到了同样的问题,发送以下标头在一台服务器上生成了 HTML 电子邮件,但在另一台服务器上不起作用
事实证明,
\r\n
是服务器的重复换行符。因此,仅使用 \n 作为换行符对我有用。Had the same problem, where sending following header produced a HTML-Email on one server but didn't work on another server
It turned out, that the
\r\n
was a duplicate linebreak for the server. So just using \n as a line break worked for me.PHP 手册网站(此处)上有一个很好的示例,展示了如何做这个。尝试复制并粘贴示例 4。
看起来您没有在标头中正确发送用于识别内容类型的字符串。如果您无法从手册中获得正确的信息,也许您应该在 Gmail 中执行“显示原始内容”,并将标题也发布到此处。
There is a good example on the PHP manual site (here) that shows how to do this. Try copy and paste example 4.
It looks like you are not sending the string to identify the content type through in the headers properly. Maybe you should do a "show original" in Gmail and post the headers here as well if you can't get it right from the manual.
看起来
MIME-Version
后面的空行表明标头已经结束,因此它将Content-Type
行作为常规文本输出,及其后面的html,而不是将该行作为标头的一部分读取,以了解将其余部分转换为 HTML。尝试获取生成标头的任何内容,以删除
MIME-Version
和Content-Type
之间的空行。 (例如,该行上是否有额外的\r\n
?生成这些行的代码是什么样的?)还可以在Content 之间添加第二个空行-类型
和。
It looks like the blank line after
MIME-Version
indicates that the header is over, so it is outputting theContent-Type
line as regular text, and the html after it, instead of reading that line as part of the header to know to convert the rest to HTML.Try getting whatever is generating your headers to remove the blank line between
MIME-Version
andContent-Type
. (For instance, do you have an extra\r\n
on that line? What does your code look like where these lines are being generated?) Also maybe add a second blank line betweenContent-Type
and<html>
.试试这个..
Try this..
标头问题在 php mail() 函数中得到解决。
Header problem was solved in php mail() function.
将此包含在您的邮件标头中
include this in your mail header
尝试使用 charset=UTF-8 而不是 ISO-8859-1...
Try using charset=UTF-8 instead of ISO-8859-1...