【问题标题】:wordpress wp_mail is sending my html message as a text attachmentwordpress wp_mail 将我的 html 消息作为文本附件发送
【发布时间】:2015-02-26 19:42:35
【问题描述】:

这是发送邮件的代码:

$to = $_POST['leadEmail'];
$subject = "my subject";
$message = ( $_POST['leadEmailPref'] == "html" ) ? $messageh : $messagep ;
$headers[] = "From: My Name <ny_name@gmail.com>";
$headers[] = "Content-type: ".$_POST['leadEmailPref'] ;

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

当我转到收件箱时,邮件作为附件发送,我看不到邮件。显然我不想要附件,我希望收到邮件的人立即看到邮件。

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    您的Content-type: 错误。应该是text/htmltext/plain,而不是html

    $headers[] = "Content-type: text/".$_POST['leadEmailPref'] ;

    【讨论】:

    • 你为什么不转义 $_POST['leadEmailPref'] ?人们可以插入额外的电子邮件标题
    【解决方案2】:

    你应该试试:

    add_filter( 'wp_mail_content_type', 'set_html_content_type' );
    
    wp_mail( 'To Email', 'Subject', '<h1>Html Email</h1>' );
    
    function set_html_content_type() {
        return 'text/html';
    }
    
    remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
    

    【讨论】:

    • 如何将 1 个包含动态数据的表格附加到电子邮件内容中?
    猜你喜欢
    • 2015-10-16
    • 2019-07-02
    • 1970-01-01
    • 1970-01-01
    • 2021-07-06
    • 2017-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多