希望在一段代码中得到一些帮助,我正在使用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'], ENT_QUOTES, 'UTF-8');
//$compact['message'] = et_get_mail_header().$compact['message'].et_get_mail_footer();
return $compact;
}
发布于 2015-04-19 07:44:34
而不是改变这一点,将您的普通换行符更改为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;
}
https://stackoverflow.com/questions/29726989
复制