css - HTML 格式的电子邮件在 Gmail 中根本不显示,但在其他邮件客户端中显示

标签 css gmail html-email gmail-imap

我目前正在从 PHP 的 mail() 函数发送 html 格式的电子邮件,并简单地检查它们以确保它们显示为 HTML(除了格式,我很清楚客户端的格式会有所不同(可能会有很大差异)给客户)。它们在 Apple Mail 客户端和我的 iPhone 上显示为 HTML。但是,Gmail 只是拒绝将其全部显示为 HTML。我并不是说它的格式不正确,它只是没有使用它出现的 HTML。

奇怪的是正在加载来自标签的 img,但仅此而已...是不是我主要使用 div 进行布局,这对于 Gmail 或其他东西(相对于表格)来说太新了吗?

就 CSS 和不符合的内容而言,查看原始源代码显示如下:

<html><head><style>body { background-color: #F2F2F2; font-family: Arial; color: #5C5C5C; font-size: 11pt; } a { color: #46AAFF; text-decoration: none; } #container { width: 750px; margin-right: auto; margin-left: auto; } #header { float: right; padding: 3px; height: 30px; } #header a { color: #666666; margin-right: 10px; } #mainBody { padding: 20px; background-color: #FFF; border: 1px solid #DADADA; border-radius: 3px; } #imageArea { border-top: solid #E8E8E8 1px; margin: 15px; } #singleImageArea { width: 250px; padding: 15px; } #singleImageArea p { float: right; line-height: 30px; width: 130px; margin-top: 20px; } #footer { padding: 10px; color: gray; } #footer p { text-shadow: 0px 2px #FFF; font-size: 10pt; } #footer a { color: #ADADAD; float: right; padding-left: 20px; padding-right: 20px; } #footer img { width: 35px; height: 23px; padding: 10px; float: left; } </style></head><body><div id="container"><div id="header"><a href="http://appname.local/login/">Login</a></d
 iv><div style="clear: both;"></div><div id="mainBody"><h1>Hi Josh Holat!</h1>You've sent a request to <strong>reset</strong> your appname password. Just click the link below <em>(or copy and paste it into your browser)</em> and follow the instructions to set a new password. The link will expire in one hour.<br/><br/><a href="http://appname.local/sb/reset-password/?r=2768af61698fcde9c04f9449351575d6bfe6d720">http://appname.local/sb/reset-password/?r=2768af61698fcde9c04f9449351575d6bfe6d720</a><br/><br/>If you feel this request was submitted in error, don't worry; you can safely ignore this e-mail and your password will not be changed.<br/><br/>Much Love,<br/>Us</div><!-- #mainBody --><div id="footer"><img src="http://appname.local/images/email/footer_sb.png" /><p>&copy; 2011 appname, Inc. All Rights Reserved <a href="http://appname.local/sb/legal/">Legal</a><a href="http://appname.local/sb/contact/">Contact</a><a href="http://s
 tagebloc.local/sb/developers/">Developers</a><a href="http://appname.local/sb/blog/">Blog</a></p></div><!-- #footer --></div><!-- #container --></body></html>

还有:

    Delivered-To: appname@gmail.com
Received: by 10.229.40.2 with SMTP id i2cs133298qce;
        Sun, 28 Aug 2011 14:29:08 -0700 (PDT)
Received: by 10.42.152.199 with SMTP id j7mr4419937icw.417.1314566947950;
        Sun, 28 Aug 2011 14:29:07 -0700 (PDT)
Return-Path: <_www@joshholat.local>
Received: from joshholat.local (arh2281.urh.uiuc.edu [130.126.70.193])
        by mx.google.com with ESMTP id w3si6800550icz.109.2011.08.28.14.29.06;
        Sun, 28 Aug 2011 14:29:06 -0700 (PDT)
Received-SPF: neutral (google.com: 130.126.70.193 is neither permitted nor denied by best guess record for domain of _www@joshholat.local) client-ip=130.126.70.193;
Authentication-Results: mx.google.com; spf=neutral (google.com: 130.126.70.193 is neither permitted nor denied by best guess record for domain of _www@joshholat.local) smtp.mail=_www@joshholat.local
Received: by joshholat.local (Postfix, from userid 70)
    id 775063662E01; Sun, 28 Aug 2011 16:29:06 -0500 (CDT)
To: Josh Holat <appname@gmail.com>
Subject: Password Reset Request
X-PHP-Originating-Script: 501:Email.php
From: appname <noreply@appname.com>
Content-type: text/html
Message-Id: <20110828212906.775063662E01@joshholat.local>
Date: Sun, 28 Aug 2011 16:29:06 -0500 (CDT)

我很困惑为什么第三方客户端可以正常显示但 Gmail 却忽略它?

最佳答案

我正在更新我的答案,因为它有很多观点,并且有新工具可用。我将原来的答案留给后代。

编辑 * 2019 年 9 月 19 日

您可以在此处找到电子邮件客户端对 CSS 属性的支持: https://www.caniemail.com/


原答案:

Gmail 不支持 <style>标签。您需要为 gmail 使用内联 css 才能正常工作。

这是一个引用列表。 http://www.campaignmonitor.com/css/

关于css - HTML 格式的电子邮件在 Gmail 中根本不显示,但在其他邮件客户端中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7224195/

相关文章:

html 电子邮件未在浏览器中显示

email - 如何从openshift服务器内部通过gmail-account使用javamail发送电子邮件?

Gmail/移动/iOS/深色模式下不显示 HTML 电子邮件背景颜色

html - 页脚 html 也显示在下方

css - 用 CSS 制作一个 2X5 的表格?

javascript - 为什么 css transition 在显示元素时发生,但在隐藏时不发生?

php - Gmail 电子邮件地址提取器

java - 如何使条形图透明

Gmail 中的 HTML 电子邮件液体布局中断

html - 是否有适用于 Gmail 应用程序的媒体查询的解决方法/替代方法?