font-style 和 font-size 在发送到 Gmail 的 HTML 电子邮件中不起作用
font-style and font-size not working in HTML email sent to Gmail
我无法让 font-style: italic
和 font-size:11px
使用 HTML 格式的电子邮件在 Gmail 中正确显示。为什么?
<p style="font-size: 11px; font-style: italic; line-height: 1.5; word-break: break-word; text-align: center; mso-line-height-alt: 21px; margin: 0;">
<span style="font-size: 11px; font-style: italic; color: #2C3E50;">Some countries and/or payment systems are not yet supported for buy and cash-out functions.<br>Please read our <a href="https://test.com/faq/?Display_FAQ=1984">FAQ</a> for more information.</span>
</p>
直接打开 HTML 在浏览器中看到的内容(好):
我在 Gmail 中看到的(不好):
我用 http://premailer.dialect.ca/ and it doesn't say anything is wrong in this regard. I checked many answers on Whosebug but none helped: 1,
验证了 HTML
我正在使用 PHPMailer. On server, we use ssmtp 发送电子邮件以发送电子邮件。这是 PHPMailer 代码:
function send_email($address, $subject, $email_template_path) {
require '/home/composer/vendor/autoload.php';
$mail = new PHPMailer(true); // true` enables exceptions
try {
//Server settings
// $mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP();
$mail->Host = 'mail.smth.net';
$mail->SMTPAuth = true;
$mail->Username = 'mailer@domain.com';
$mail->Password = 'some&pas3eWer';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('info@mydomain.com', 'Info');
$mail->addAddress($address);
$mail->addReplyTo('support@mydomain.com', 'Support');
// Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = file_get_contents($email_template_path); // see https://pastebin.com/raw/WUhap2DQ
$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
问题是代码格式不正确。在其中一个 style=...
中,我遗漏了 ;
.
我无法让 font-style: italic
和 font-size:11px
使用 HTML 格式的电子邮件在 Gmail 中正确显示。为什么?
<p style="font-size: 11px; font-style: italic; line-height: 1.5; word-break: break-word; text-align: center; mso-line-height-alt: 21px; margin: 0;">
<span style="font-size: 11px; font-style: italic; color: #2C3E50;">Some countries and/or payment systems are not yet supported for buy and cash-out functions.<br>Please read our <a href="https://test.com/faq/?Display_FAQ=1984">FAQ</a> for more information.</span>
</p>
直接打开 HTML 在浏览器中看到的内容(好):
我在 Gmail 中看到的(不好):
我用 http://premailer.dialect.ca/ and it doesn't say anything is wrong in this regard. I checked many answers on Whosebug but none helped: 1,
我正在使用 PHPMailer. On server, we use ssmtp 发送电子邮件以发送电子邮件。这是 PHPMailer 代码:
function send_email($address, $subject, $email_template_path) {
require '/home/composer/vendor/autoload.php';
$mail = new PHPMailer(true); // true` enables exceptions
try {
//Server settings
// $mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP();
$mail->Host = 'mail.smth.net';
$mail->SMTPAuth = true;
$mail->Username = 'mailer@domain.com';
$mail->Password = 'some&pas3eWer';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('info@mydomain.com', 'Info');
$mail->addAddress($address);
$mail->addReplyTo('support@mydomain.com', 'Support');
// Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = file_get_contents($email_template_path); // see https://pastebin.com/raw/WUhap2DQ
$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
问题是代码格式不正确。在其中一个 style=...
中,我遗漏了 ;
.