首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将背景颜色添加到php mail()发送的html电子邮件中

问如何将背景颜色添加到php mail()发送的html电子邮件中
EN

Stack Overflow用户
提问于 2017-06-20 02:54:26
回答 3查看 3.9K关注 0票数 3

我试图添加这个html电子邮件的背景色。

我试着把

  • 包含css代码的<script>标记
  • 体标签中的bgcolor
  • 和css样式表 所有这些都不起作用。我读到它可能是我发送这些测试的提供者(gmail),但是必须有一个方法。

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

代码语言:javascript
复制
    $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);
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-06-20 03:01:36

这样做:

代码语言:javascript
复制
  <body style="background-color:#cfcfcf";>
票数 4
EN

Stack Overflow用户

发布于 2017-06-20 04:06:57

关于电子邮件,首先要知道的是扔掉你所知道的所有关于网络标准的东西。电子邮件还在90年代,你看看石蕊和MailChimp在说些什么。

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

然后用那张桌子的颜色给你的邮件背景涂上颜色。

忘记使用外部样式表或使用<style>标记将CSS放在头上。他们被各种各样的读者剥夺了。您必须在html标记中执行内联样式。

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

票数 1
EN

Stack Overflow用户

发布于 2017-06-20 04:11:13

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

另外,您可以在html代码中编写内联css。

  • 如果您使用的是外部css,那么它可能无法在gmail收件箱中找到css的路径。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44643047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档