【发布时间】:2016-05-11 16:29:54
【问题描述】:
我有通过 PHP 发送 HTML 电子邮件的代码。它有一张桌子。我想在屏幕截图中加粗圆形。但是到达 Gmail 的电子邮件没有显示粗体和其他应该应用于“关于”类选择器的更改。
我可以在 PHP HTML 电子邮件的样式表中使用类或 ID 选择器吗?我不喜欢使用内联 CSS,因为它效率低下。我在身体之间使用过它们。 这是代码;
$to = "xxxx@gmail.com, xxxx@gmail.com"; //multiple recipients with comma separated
$subject = "Here is the subject"; //cannot contain newline characters
$message = "<h1>This is Heading H1</h1>";
$message .= "This is my <b>first</b> line of text.<br>This is my <b>second</b> line of text<br><br>"; //each line should be separated with (\n).
$message .= "<html>
<head>
<style>
body{
color:#000000;
background-color:#FFFFFF;
font-family:arial, verdana, sans-serif;
}
h1{
font-size:18px;
}
p{
font-size:12px;
}
table{
background-color:#efefef;
border-style:solid;
border-width:1px;
border-color:#999999;
}
th{
background-color:#cccccc;
font-weight:bold;
padding:5px;
}
td{
padding:5px;
}
td.about{
font-family:courier, courier-new, serif;
font-weight:bold;
}
</style>
</head>
<body>
<table>
<tr>
<th> About </th>
<th> Description </th>
</tr>
<tr>
<td class=\"about\"> Name </td>
<td> Andreas </td>
</tr>
<tr>
<td class=\"about\"> Address </td>
<td> Germany </td>
</tr>
<tr>
<td class=\"about\"> Message </td>
<td> I like your 8 day tour package. What are the rates? </td>
</tr>
</table>
</body>
</html>
";
//headers like From, Cc, Bcc, Reply-to, Date ???????????
//$header = "From:raveen1231@gmail.com \r\n";
$header = "From: RXXXXX CXXXXX <rxxxx1111@gmail.com> \r\n"; //additional headers should be separated with (\r\n)
//$header .= "Cc: rxxxxx111@gmail.com \r\n";
//$header .= "Bcc: rxxxxx222@gmail.com \r\n";
//always specify MIME version, content type, and character set when sending HTML email
$header .= "MIME-Version: 1.0 \r\n";
$header .= "Content-type:text/html;charset=UTF-8 \r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; //////////////////////////////Pls Delete later
$retval = mail( $to, $subject, $message, $header );
if( $retval == true ){
echo "Message sent successfully";
}
else{
echo "Message could not be sent!";
}
【问题讨论】:
-
你在你的 css 上是否只尝试过
.about{...? -
@PedroLobito 先生,我检查了所有这些变化: .ab{... , td.ab{... 。但是gmail不识别类名。但雅虎显示正确
-
简短的回答是,对于 HTML 电子邮件,您将需要内联您的 CSS 以获得不同电子邮件客户端之间的一致性。 HTML 电子邮件是出了名的棘手,因为每个电子邮件客户端都会以不同的方式呈现 CSS 和格式。
-
手动内联 CSS 确实是低效的。你会需要一个预发邮件(有很多,premailer.dialect.ca 就是一个例子)为你做这件事。
-
@ceejayoz 非常有用的信息。谢谢
标签: php