在 wordpress 中使用 wp_mail 发送 HTML 和纯文本电子邮件

问题描述

我想在 wordpress 中使用 wp_mail() 函数发送 HTML 和纯文本电子邮件

我找不到办法做到这一点。 有人知道怎么做吗?

例如在 PHPMailer 中,有一个选项可以用这一行设置 HTML 和文本:

$mail->AltBody = $plain_text_format_mail;

有人知道 wp_mail 是否有类似的东西可以让我同时发送 html 作为主要电子邮件和文本作为故障安全选项吗?

谢谢

解决方法

对 HTML 电子邮件使用 Content-Type: text/html

$to      = '[email protected]';
$subject = 'The subject';
$body    = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');

wp_mail( $to,$subject,$body,$headers );

Content-Type: text/plain 用于普通电子邮件。

$to      = '[email protected]';
$subject = 'The subject';
$body    = 'The email body content';
$headers = array('Content-Type: text/plain; charset=\"utf-8\"\r\n');

wp_mail( $to,$headers );