如何为使用 php mail() 发送的 html 电子邮件添加背景颜色
how to add background color to html email sent with php mail()
我正在尝试为此 html 电子邮件添加背景颜色。
我试过
<script>
内含 css 代码的标签
正文标签中的 bgcolor
和css风格sheet
所有这些都不起作用。
我读到它可能是我将这些测试发送到的提供商 (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);
这样试试:
<body style="background-color:#cfcfcf";>
了解电子邮件的第一件事就是扔掉你所知道的关于网络标准的一切。电子邮件仍处于 90 年代。看看 Litmus 和 MailChimp 是怎么说的。
- 使用table进行设计。
- 使用 tables 作为容器。将整条消息包装在单列单行中 table.
然后 use the bgcolor of that table 为电子邮件的背景着色。
忘记使用外部样式 sheet 或将 CSS 放在带有 <style>
标签的头部。他们被各种读者剥夺了。您必须在 html 标签中添加内联样式。
是的,它违背了 CSS 的全部目的。但正如我所说,电子邮件不遵循标准。落后了。
如果您使用的是电子邮件模板,那么您可以内嵌 css 以及在标签中嵌入 css。
否则,您可以在 html 代码中编写内联 css。
- 如果您使用的是外部 css 那么它可能无法在 gmail 收件箱中使用找不到 css.
路径的电子邮件
我正在尝试为此 html 电子邮件添加背景颜色。
我试过
<script>
内含 css 代码的标签正文标签中的 bgcolor
和css风格sheet
所有这些都不起作用。 我读到它可能是我将这些测试发送到的提供商 (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);
这样试试:
<body style="background-color:#cfcfcf";>
了解电子邮件的第一件事就是扔掉你所知道的关于网络标准的一切。电子邮件仍处于 90 年代。看看 Litmus 和 MailChimp 是怎么说的。
- 使用table进行设计。
- 使用 tables 作为容器。将整条消息包装在单列单行中 table.
然后 use the bgcolor of that table 为电子邮件的背景着色。
忘记使用外部样式 sheet 或将 CSS 放在带有 <style>
标签的头部。他们被各种读者剥夺了。您必须在 html 标签中添加内联样式。
是的,它违背了 CSS 的全部目的。但正如我所说,电子邮件不遵循标准。落后了。
如果您使用的是电子邮件模板,那么您可以内嵌 css 以及在标签中嵌入 css。
否则,您可以在 html 代码中编写内联 css。
- 如果您使用的是外部 css 那么它可能无法在 gmail 收件箱中使用找不到 css. 路径的电子邮件