【问题标题】:Send both HTML and Plain Text emails using wp_mail in wordpress在 wordpress 中使用 wp_mail 发送 HTML 和纯文本电子邮件
【发布时间】:2021-07-06 04:41:33
【问题描述】:

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

我无法找到一种方法来做到这一点。 有人知道怎么做吗?

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

$mail->AltBody = $plain_text_format_mail;

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

谢谢

【问题讨论】:

    标签: wordpress wp-mail


    【解决方案1】:

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

    $to      = 'test@example.com';
    $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      = 'test@example.com';
    $subject = 'The subject';
    $body    = 'The email body content';
    $headers = array('Content-Type: text/plain; charset=\"utf-8\"\r\n');
    
    wp_mail( $to, $subject, $body, $headers );
    

    【讨论】:

    • 您好,感谢您的回答,我想同时发送一封邮件,而不是一封文本邮件和一封 html 邮件。过去,这是我们对不支持 html 的旧电子邮件软件所做的。
    • 谢谢,那篇文章的解决方案似乎有点乱。他们都在使用过滤器,有些选项非常复杂,从长远来看可能会导致问题。我希望 wp_mail 有更简单的解决方案,但如果不可能,只使用 html 版本会更安全。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-28
    • 1970-01-01
    • 2017-04-23
    • 2010-11-10
    相关资源
    最近更新 更多