簡體   English   中英

HTML 格式的電子郵件根本不顯示在 Gmail 中,但在其他郵件客戶端中

[英]HTML formatted email not showing up at all in Gmail but is in other mail clients

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

我正在更新我的答案,因為它有很多視圖,並且有新工具可用。 我將我的原始答案留給后人。

編輯 * 19 年 9 月 19 日

您可以在此處通過電子郵件客戶端找到 CSS 屬性支持: https : //www.caniemail.com/


原答案:

Gmail 不支持<style>標簽。 您需要使用內聯 css 才能讓 gmail 正常工作。

這是一個參考列表。 http://www.campaignmonitor.com/css/

GMail不支持<style>標簽,許多客戶端也不支持 為了讓您的生活更輕松,您可以使用 convert 將您的樣式標簽轉換為內聯 CSS: https : //templates.mailchimp.com/resources/inline-css/

上面的回答都不錯,只是想補充幾點。 此鏈接的所有功勞:

  1. Gmail 僅支持<head>中的<head> <style> <head> Gmail 確實支持嵌入樣式 ( <style> )。 但是,僅 HTML 文檔的頭部支持嵌入樣式。 Gmail Android 和 iOS 應用程序在呈現通過非 Google 帳戶 (GAGA) 檢索的電子郵件時根本不支持<style>

  2. 如果遇到錯誤,Gmail 會刪除您的整個<style>塊。

  3. Gmail 不允許負 CSS 邊距值。

  4. Gmail 不支持屬性選擇器和大多數偽類。 例如div[class="content"]{ color: red } Gmail 也不支持像:checked:active這樣的偽類。

我看到您正在使用名為 #footer 的 ID。 Google 在處理郵件時似乎無法識別該名稱。 請注意,在從 gmail 看到的字體代碼中,您的所有 ID 都可能以“exc”+ idName 顯示,除了 #footer。 嘗試使用不同的名稱。

這有點晚了,但在將郵件 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" 並保存模板並在您的工作中使用。

完畢。 它對我有用。

通過清除瀏覽器中的瀏覽數據然后加載 gmail 來做到這一點。 它仍然會顯示 html 內容。 在同一頁面上做硬刷新。

蘋果:

Command+Shift+R
視窗:
  Ctrl+Shift+R

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM