php - 使用 PHPMailer 发送的电子邮件会忽略 CSS 样式
问题描述
我正在使用 PHPMailer (SMTP) 发送一封简单的电子邮件。在这里,我遇到了 CSS 格式的问题。一般来说,像颜色变化这样的事情是有效的。但是其他诸如更改字体大小之类的事情不起作用。电子邮件客户端忽略了我的风格。我正在使用火花。但我不认为问题出在客户身上。我还收到其他 HTML 电子邮件。
这是我的代码:
$email_body = "
<html>
<head>
<style>
span {
font-family: Verdana, Geneva, sans-serif;
font-size:12px;
color:#FF0000;
}
h2 {font-size: 50px}
</style>
</head>
<body>
<div>
Hi there,<br><br>
this is just a test e-mail.
<br><br>
<h2 style='color: darkblue;font-size:50px'>This is a headline</h2><br><br>
<span>This is just a text</span>
</div>
</body>
</html>
";
try {
//Server settings
$mail->isSMTP();
.....
$mail->Port = 587;
//Recipients
$mail->setFrom('email@email.de', 'John Doe');
$mail->addAddress('email@email.de', 'John Doe'); //Add a recipient
$mail->addReplyTo('noreply@email.de', 'Information');
$mail->CharSet = 'UTF-8';
//Attachments
$path = '../tempfiles/';
$files = preg_grep('/^([^.])/', scandir($path));
foreach ($files as $f) {
if (in_array($f, $file_names_arr)) {
$mail->addAttachment("../tempfiles/" . $f);
}
}
//Content
$mail->isHTML(true);
$mail->Subject = 'Email Subject';
$mail->Body = $email_body;
$mail->AltBody = "Test";
$mail->send();
// Delete images afterwards
$path = '../tempfiles/';
$files = preg_grep('/^([^.])/', scandir($path));
foreach ($files as $f) {
if (in_array($f, $file_names_arr)) {
if (is_file("../tempfiles/" . $f)) {
unlink("../tempfiles/" . $f);
}
}
}
echo json_encode(1);
} catch (Exception $e) {
echo json_encode(0);
}
所有排版元素,如 h2、h3、p、span 都具有相同的字体大小,我无法更改。这里可能是什么问题?
解决方案
推荐阅读
- python - Python 到 C 浮点不精确
- javascript - Netsuites SuiteScript 框架能否用于根据对脚本 url 的 GET 请求返回信息
- snowflake-cloud-data-platform - 使用 Snowflake+DBT 时随机发生无效的 JWT 令牌
- r - 在R中的坐标周围绘制多边形
- javascript - 在 React Native 中使用 readAsStringAsync 将图像数组转换为 base64
- r - 用多列中的多个值替换多个字符?R
- angular - Angular Guards:防止手动访问 URL 但授权刷新
- java - Java中的计算器,显示错误的功能。网豆
- regex - Notepad++ 中的 RegEx 查找管道少于或多于 n 个的行
- python - 根据文件名填充 NaN