Elc*_*gri 7 php wordpress mime function
希望得到一些代码的帮助,我使用wordpress的主题,将邮件头设置为text/html,这导致纯文本邮件ex的一些问题.换行符不再显示.
我尝试过设置:
} else {
return 'text/plain';
}
Run Code Online (Sandbox Code Playgroud)
但我不太清楚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'], ENT_QUOTES, 'UTF-8');
//$compact['message'] = et_get_mail_header().$compact['message'].et_get_mail_footer();
return $compact;
}
Run Code Online (Sandbox Code Playgroud)
不要更改它,而是将普通换行符更改为 html。
$message=nl2br($message); // of course use your var name.
Run Code Online (Sandbox Code Playgroud)
这样您也可以保持电子邮件的标准格式。在这种情况下,纯文本没有什么特别之处需要单独的标题。此函数会将所有换行符转换为 html 版本。
除了新行之外,大多数纯文本即使在 html 中也会保留其格式,因为它没有特殊标签。
这是您将如何放置它
function wp_mail($compact) {
// leave your existing code intact here, don't remove it.
$compact["message"]=nl2br($compact["message"]);
return $compact;
}
Run Code Online (Sandbox Code Playgroud)