解決 BlueHost 上的 wordpress 發信亂碼

上個月把網站搬到 bluehost,可以感覺網站的開啟速度快了不少。然而還是有一點小缺陷,那就是 PHP 的發信亂碼。

一開始跟著 bluehost 的設定說明去修改 php.ini 也不見好轉。

後來才發現原來只要將信件內文以 base64 格式發送就好了,瞎忙一場。

php · [高亮] · [原始]

  1. function wp_mail($to, $subject, $message, $headers=) {
  2.     $n = "\n";
  3.     $charset = get_option(‘blog_charset’);
  4.  
  5.     if ($headers == ) {
  6.         $headers = ‘MIME-Version: 1.0′.$n.
  7.             ‘From: wordpress@’.preg_replace(‘#^www\.#’, , strtolower($_SERVER[‘SERVER_NAME’])).$n .
  8.             ‘Content-Type: text/plain; charset="’.$charset.‘"’.$n;
  9.     }
  10.  
  11.     if (strpos($headers, ‘Content-Transfer-Encoding’) === false)
  12.         $headers .= ‘Content-Transfer-Encoding: base64′.$n;
  13.  
  14.     $subject = ‘=?’.$charset.‘?B?’.base64_encode($subject).‘?=’;
  15.     $message = base64_encode($message);
  16.  
  17.     return @mail($to, $subject, $message, $headers);
  18. }
function wp_mail($to, $subject, $message, $headers=\'\') {
	$n = "\\n";
	$charset = get_option(\'blog_charset\');

	if ($headers == \'\') {
		$headers = \'MIME-Version: 1.0\'.$n.
			\'From: wordpress@\'.preg_replace(\'#^www\\.#\', \'\', strtolower($_SERVER[\'SERVER_NAME\'])).$n .
			\'Content-Type: text/plain; charset="\'.$charset.\'"\'.$n;
	}

	if (strpos($headers, \'Content-Transfer-Encoding\') === false)
		$headers .= \'Content-Transfer-Encoding: base64\'.$n;

	$subject = \'=?\'.$charset.\'?B?\'.base64_encode($subject).\'?=\';
	$message = base64_encode($message);

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

3 Responses to “解決 BlueHost 上的 wordpress 發信亂碼”

  1. lwkyy Says:

    请问一下你blog里用的代码高亮插件是什么啊,能不能公布出来啊,
    我挺喜欢这个高亮插件的~~

  2. Pedestrian counter Says:

    Pedestrian counter…

    好有趣啊,呵呵!…

  3. smartwen Says:

    原來如此

Leave a Comment