【问题标题】:how to add background color to html email sent with php mail()如何为使用 php mail() 发送的 html 电子邮件添加背景颜色
【发布时间】:2017-11-22 09:45:48
【问题描述】:

我正在尝试为此 html 电子邮件添加背景颜色。

我试过了

  • <script> 内部带有 css 代码的标签

  • body标签中的bgcolor

  • 还有一个 CSS 样式表

    所有这些都不起作用。 我读过它可能是我将这些测试发送给的提供商 (gmail),但必须有办法。

我在一个单独的 .html 文件上测试的所有方法都已更改为我想要的。我只是无法在实际的电子邮件中得到它。我在 php 中使用 mail()。

    $message = "
    <html>
    <head>
    <title>Rate Your Experience</title>
    </head>
    <body bgcolor = '#0000FF'>
    <center>
    
    <p>
        <h2>How well did '$recipient' do?</h2>
        <h4>Vacancy Title: '$vac_title'</h4>
        <h4>Vacancy ID: '$vac_id'</h4>
    </P>
    </center>
    <center>
        <table>
        <tr>
        <td><h3>we are built on sharing your review with other people who may also want to use this service.</h3></td>
        </tr>
        <tr>
        <td><h3>Please take a minute to reflect on the level of service youve received.</h3></td>
        </tr>
        <tr>
        <td><h3>Your review is public - to other employers registered with Ahoy Employ.</h3></td>
        </tr>
        <tr>
        <td><h3>Should you have any concerns that you would prefer to share in private, please email us at info@website.ca and quote the Vacancy ID shown above.</h3></td>
        </tr>
        </table>
    </center>
    </body>
    </html>
    ";

    // Always set content-type when sending HTML email
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

    // More headers
    $headers .= 'From: <webmaster@provider.ca>' . "\r\n";

    mail($to,$subject,$message,$headers);

【问题讨论】:

  • 您可以为 Example(&lt;body style="background-color:#0000FF";&gt;) 编写内联式表单电子邮件
  • 基本的内联 CSS 将满足您的需求。

标签: php html css html-email email


【解决方案1】:

试试这样:

  <body style="background-color:#cfcfcf";>

【讨论】:

  • 内联 CSS 工作它只需要单引号而不是双引号。
【解决方案2】:

首先要了解电子邮件,就是扔掉您对 Web 标准的所有了解。电子邮件仍处于 90 年代。看看 Litmus 和 MailChimp 在说什么。

  1. 使用表格进行设计。
  2. 将表格用作容器。将整条消息包装在一个单列单行表格中。

然后use the bgcolor of that table 为您的电子邮件背景着色。

忘记使用外部样式表或将 CSS 与 &lt;style&gt; 标签放在头部。它们被各种读者剥离。你必须在 html 标签中做内联样式。

是的,它违背了 CSS 的全部目的。但就像我说的,电子邮件不符合标准。太落后了。

【讨论】:

    【解决方案3】:

    如果您使用的是电子邮件模板,那么您可以编写内联 css 以及在标签中嵌入 css。

    否则,您可以在 html 代码中编写内联 css。

    • 如果您使用的是外部 css,那么它可能无法正常工作 gmail 收件箱中的电子邮件找不到 css 的路径。

    【讨论】:

      猜你喜欢
      • 2023-04-09
      • 2012-03-18
      • 2023-03-17
      • 1970-01-01
      • 2020-07-07
      • 1970-01-01
      • 1970-01-01
      • 2013-02-22
      • 2015-07-19
      相关资源
      最近更新 更多