是否可以使用具有 Content-Type: multipart/alternative 的 wp_mail() 函数发送电子邮件?
我需要发送可以显示为 HTML 或纯文本的电子邮件,具体取决于解释电子邮件的媒体。
欢迎任何建议!
最佳答案
当您可以访问 phpmailer 实例时,这是完全可能的。
if ($is_html)
add_action('phpmailer_init', 'fix_mimeheader');
// more code.
wp_mail( $to, $subject, $html_message, $headers, $attachments );
// ...
function fix_mimeheader( $phpmailer ) {
// Generate $text_message here.
// ...
$phpmailer->AltBody = $text_message;
}
发送到 wp_mail 的消息应该是您的 html 代码。您也不应该包含任何内容类型标题。我目前在我制作的插件中使用 from、cc 和 reply-to。
如果电子邮件以 HTML 格式发送,我会运行直接在 phpmailer 对象上设置 AltBody 属性的操作。然后这会导致正确的标志将电子邮件转换为多部分/替代电子邮件。
关于wordpress - 内容类型:带有 wp_mail() 的 Wordpress 中的 multipart/alternative,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20353390/