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

1rhkuytd  于 2023-05-19  发布在  其他
关注(0)|答案(6)|浏览(220)

我目前正在从PHP的mail()函数发送HTML格式的电子邮件,并检查它们,以确保它们显示为HTML(除了格式,我很清楚格式会因客户端而异(可能会有很大的差异))。它们在苹果邮件客户端和我的iPhone上都显示为HTML。然而,Gmail只是拒绝将其显示为HTML。我并不是说它的格式不正确,它只是没有使用HTML。
奇怪的部分是,一个img从一个标签正在加载,但仅此而已…是因为我主要使用div来布局,这对Gmail或其他东西来说太新了吗(vs表)?
就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只是忽略它?

mlnl4t2r

mlnl4t2r1#

我正在更新我的答案,因为它有相当多的视图,并且有新的工具可用。我把我最初的答案留给后人。
编辑 * 9/19/19
你可以在这里找到通过电子邮件客户端的CSS属性支持:https://www.caniemail.com/
原始答案:
Gmail不支持<style>标签。你需要使用内联css来让gmail正常工作。
这是一个参考清单。http://www.campaignmonitor.com/css/

55ooxyrt

55ooxyrt2#

GMail doesn't support<style>标签,许多客户端也不支持。为了让你的生活更轻松,你可以使用convert将你的样式标签转换为内联CSS:https://templates.mailchimp.com/resources/inline-css/

8hhllhi2

8hhllhi23#

上面的答案都很不错,只是想再补充几点。this link的所有信用:
1.**Gmail仅支持<head>中的<style>。**Gmail支持嵌入式样式(<style>)。但是,嵌入式样式仅在HTML文档的头部受支持。Gmail Android和iOS应用程序在呈现通过非Google帐户(GANGA)检索的电子邮件时根本不支持<style>

  1. Gmail会在遇到错误时删除整个<style>区块。
  2. Gmail不允许负的CSS边距值。
  3. Gmail不支持属性选择器和大多数伪类。例如div[class="content"]{ color: red }。Gmail也不支持:checked:active等伪类。
    编辑:在3年后的回顾中,Gmail CSS是相当奇怪的。
6pp0gazn

6pp0gazn4#

这有点晚了,但我也面临着同样的问题后,改变邮件SMTP从Outlook到Gmail。由于Gmail不再支持Style标签,因此电子邮件不是默认的预期模板格式。下面的解决方案为我工作:
1.将默认电子邮件模板代码复制到.jenkins目录下的email-templates文件夹中。复制模板的链接:https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/resources/hudson/plugins/emailext/templates/groovy-html.template
1.将样式标记的属性从STYLE更改为STYLE type="text/css" data-inline="true",并保存模板并在作业中使用它。
好了。对我很有效。

fumotvh3

fumotvh35#

我看到你正在使用一个名为#footer的ID。看来谷歌在处理邮件时并不认可这个名字。请注意,在gmail中看到的字体代码中,除了#footer之外,您的所有ID都可能以“exc”+ idName显示。尝试使用不同的名称。

pcww981p

pcww981p6#

从浏览器中清除浏览数据,然后加载Gmail。它仍然会显示HTML内容。在同一页面上进行硬刷新。
麦克:

Command+Shift+R

Windows:

Control+Shift+R

相关问题