修正Comment亂碼

其實這個問題存在己久,每次有人迴響收到mail通知時主旨總是秀出亂碼,只是影響不大,所以就沒有理它,直到今天在"Windix"的網站中看到解法才將問題解決。不過"Windix"使用外掛的方式我行不通,有可能我不是1.52的版本,所以我改用另一個方法,將 wp-includes/function.php中function wp_mail($to, $subject, $message, $headers = '', $more = '') 整段function mark 起來


/*
function wp_mail($to, $subject, $message, $headers = '', $more = '') {
if( $headers == '' ) {
$headers = "MIME-Version: 1.0n" .
"Content-Type: text/plain; charset="" . get_settings('blog_charset') . ""n";
}

return @mail($to, $subject, $message, $headers, $more);
}

*/

再將

"Windix"所提供utf-mail.php的程式碼


function wp_mail($to, $subject, $message, $headers = '') {

if( $headers == '' ) {
$headers = "MIME-Version: 1.0n" .
"From: " . get_settings('admin_email') . "n" .
"Content-Type: text/plain; charset="" . get_settings('blog_charset') . ""n";
}

// because WP use simple "To" field (xxx@xxx.xxx)
// There is no need for escaping "To" field.

// Deal with "subject" field
$subject = '=?UTF-8?B?'.base64_encode($subject).'?=';

// Deal with "message" field
$message = base64_encode($message);

//Deal with "headers" field
$tmp_headers = split("n",$headers);
$op_headers = array();
foreach ($tmp_headers AS $key=>$val ) {
// From
if (preg_match('/^From: "(.+)"(.*)$/',$val,$matches)) {
$op_headers[] = 'From: "'. '=?UTF-8?B?' . base64_encode($matches[1])
. '?="' . $matches[2];
}
elseif (preg_match('/^Content-Type: /',$val)) {
$op_headers[] = $val . "n" . 'Content-Transfer-Encoding: BASE64';
}
elseif (preg_match('/^Content-Transfer-Encoding: /',$val)) {
// discard original Content-Transfer-Encoding
}
else {
$op_headers[] = $val;
}
} // end foreach

$headers = join("n",$op_headers);

return mail($to, $subject, $message, $headers);
}

取代舊有的function,問題居然就解決了~~只是不確定是否會影響到wp日後的升級~~

您可能也會喜歡…

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *