php – wordpress邮件标题设置其他纯文本

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – wordpress邮件标题设置其他纯文本脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
希望得到一些代码的帮助,我使用wordpress主题,将邮件标题设置为text / htML,这导致纯文本邮件ex的一些问题.换行符不再显示.

我尝试过设置:

} else {
    return 'text/plain';
}

但是我不太了解PHP,所以我不知道在哪里放置它才能使它工作.我想为未定义的邮件设置text / plain.

这是wp头的代码

/**
 * filter mail headers
 */
function wp_mail($compact) {
    if (isset($_GET['action']) && $_GET['action'] == 'lostpassword') return $compact;
    if ($compact['headers'] == '') {

        //$compact['headers']   = 'MIME-Version: 1.0' . "\r\n";
        $compact['headers'] = 'Content-tyPE: text/html; charset=utf-8' . "\r\n";
        $compact['headers'].= "From: " . get_option('blogname') . " < " . get_option('admin_email') . "> \r\n";
    }

    $compact['message'] = str_ireplace('[sITe_url]',home_url(),$compact['message']);
    $compact['message'] = str_ireplace('[bLOGname]',get_bloginfo('name'),$compact['message']);
    $compact['message'] = str_ireplace('[admin_email]',get_option('admin_email'),$compact['message']);

    $compact['message'] = html_entity_decode($compact['message'],ENT_QUOTES,'UTF-8');
    $compact['subject'] = html_entity_decode($compact['subject'],'UTF-8');

    //$compact['message']       =   et_get_mail_header().$compact['message'].et_get_mail_footer();

    return $compact;
}
而不是更改它,将您的简单换行符更改为html.
$message=nl2br($message); // of course use your VAR name.

这样你就可以保持邮件的标准格式.在这种情况下,纯文本没有什么特别需要单独的标题.此函数会将所有换行符转换为html版本.

除了新行之外,大多数纯文本都会在html中保存其格式,因为它没有特殊标记.

以下是您将如何放置它

function wp_mail($compact) {
    // leave your existing code intact here,don't remove it.
    $compact["message"]=nl2br($compact["message"]); 
    return $compact;
}

脚本宝典总结

以上是脚本宝典为你收集整理的php – wordpress邮件标题设置其他纯文本全部内容,希望文章能够帮你解决php – wordpress邮件标题设置其他纯文本所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。