我在使用WordPress中的wp_mail()和PHPMailer发送多部分电子邮件时遇到问题。
此邮件标题:
$wp_mail_headers = array(
"From: Test <test@test.com>",
'Content-Type: multipart/alternative;
boundary="b_00cdedc7a5309e22d6d51e1ad7ad886e"',
);
使用PHPMailer发送时,将如下所示,边界消失了:
X-Mailer: PHPMailer 5.2.22 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: multipart/alternative; charset=
Content-Transfer-Encoding: quoted-printable
应该是这样的:
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="b_00cdedc7a5309e22d6d51e1ad7ad886e"
如何使用PHPMailer设置多部分电子邮件标题?
谢谢!
更新
添加过滤器怎么样?那会有用吗?例如:
add_filter( 'wp_mail', 'rw_change_email_headers' );
function rw_change_email_headers( $params )
{
$params['headers'] = 'Content-type: text/html';
return $params;
}
如果过滤器与PHPMailer一起使用,如何将其添加到下面的代码中? 是否应该使用remove_filter()?
删除过滤器$wp_mail_headers = array(
"From: Test <$wp_admin_email>",
"Bcc: test@test.com",
"Reply-To: $wp_admin_email",
'Content-Type: multipart/alternative; boundary="b_00cdedc7a5309e22d6d51e1ad7ad886e"',
);
$wp_mail_message = '--b_00cdedc7a5309e22d6d51e1ad7ad886e
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable';
$wp_mail_message .= get_field('order_email_plain_text', 'option');
$wp_mail_message .= '--b_00cdedc7a5309e22d6d51e1ad7ad886e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<!doctype html><html lang="en"><head><meta name="viewport" content="width=device-width" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Order Email</title></head><body>';
$wp_mail_message .= get_field('order_email', 'option');
$wp_mail_message .= '</body></html>
--b_00cdedc7a5309e22d6d51e1ad7ad886e--';
答案 0 :(得分:0)
PHPMailer会根据您提供的内容为您处理MIME结构。这将导致multipart/alternative
MIME结构(除了标题之外还有更多内容):
$mail->isHTML();
$mail->Body = '<h1>Hello</h1>';
$mail->AltBody = 'Hello';
同样地,除了设置from
标题之外,还有更多来自地址的内容,因此请使用PHPMailer的功能为您正确地执行此操作:
$mail->setFrom('test@test.com', 'Test');
看起来字符集也没有正确设置。你可以用以下方法解决这个问题:
$mail->CharSet = 'utf-8';
您正在使用旧版本的PHPMailer,因此我建议您升级。