【问题标题】:HTML formatted email not showing up at all in Gmail but is in other mail clientsHTML 格式的电子邮件根本不显示在 Gmail 中,但在其他邮件客户端中
【发布时间】:2011-11-05 15:43:22
【问题描述】:

我目前正在从 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 只是忽略它?

【问题讨论】:

  • 您能否发布您的一条消息的全部来源(包括标题)?
  • 您的 HTML 示例在 &lt;body&gt;-tag 开头后结束...
  • 我添加了所有的标题以及 HTML 的其余部分

标签: css gmail html-email gmail-imap


【解决方案1】:

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

编辑 * 2019 年 9 月 19 日

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


原答案:

Gmail 不支持 &lt;style&gt; 标记。您需要使用内联 css 才能使 gmail 正常工作。

这是一个参考列表。 http://www.campaignmonitor.com/css/

【讨论】:

  • 真的吗?哇。太糟糕了...感谢您的链接。
  • 哇,看到 Gmail 提供如此糟糕的支持真是太棒了,它是最受欢迎的电子邮件服务之一! Apple mail 和 Android 4 (Gmail) 在支持方面似乎遥遥领先。不过,我对 Gmail 感到非常惊讶!
  • 在邮寄之前通过this library 运行您的HTML,它将从您的脑海中获取样式并将它们解析为内联。
  • 好吧,所以这个答案已经过时了。 2019 年有人遇到这个问题吗?
  • @Solvitieg 上面的链接仍然与电子邮件客户端相关并且是最新的。是的,这对于 5 年前的电子邮件客户端来说仍然是同样的问题。
【解决方案2】:

GMail doesn't support &lt;style&gt; 标签和许多客户端也没有。为了让您的生活更轻松,您可以使用 convert 将样式标签转换为内联 CSS:https://templates.mailchimp.com/resources/inline-css/

【讨论】:

  • 这是此任务最方便的工具和链接。谢谢!
【解决方案3】:

以上回答都不错,只是想补充几点。全部归功于this link:

  1. Gmail 仅支持 &lt;head&gt; 中的 &lt;style&gt; Gmail 确实支持嵌入样式 (&lt;style&gt;)。但是,仅在 HTML 文档的头部支持嵌入样式。在呈现通过非 Google 帐户 (GANGA) 检索到的电子邮件时,Gmail Android 和 iOS 应用程序根本不支持 &lt;style&gt;

  2. 如果遇到错误,Gmail 会删除整个 &lt;style&gt; 块。

  3. Gmail 不允许负 CSS 边距值。

  4. Gmail 不支持属性选择器和大多数伪类。例如div[class="content"]{ color: red }。 Gmail 也不支持 :checked:active 等伪类。

【讨论】:

    【解决方案4】:

    我看到您使用的是名为#footer 的 ID。 在处理邮件时,Google 似乎无法识别该名称。 请注意,在从 gmail 看到的字体代码中,您的所有 ID 都可能以“exc”+ idName 出现,#footer 除外。 尝试使用其他名称。

    【讨论】:

      【解决方案5】:

      这有点晚了,但在将邮件 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

      2. 只需将样式标签的属性从 STYLE 到 STYLE type="text/css" data-inline="true" 并保存模板并在您的工作中使用。

      完成。它对我有用。

      【讨论】:

        【解决方案6】:

        通过清除浏览器中的浏览数据然后加载 gmail 来执行此操作。它仍然会显示 html 内容。在同一页面上进行硬刷新。

        苹果机:

        Command+Shift+R
        Windows:
        Control+Shift+R

        【讨论】:

          猜你喜欢
          • 2018-07-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-11-20
          • 1970-01-01
          • 1970-01-01
          • 2023-03-28
          • 2013-05-26
          相关资源
          最近更新 更多