WordPress 通知郵件標題的亂碼

因為 WordPress 的 wp_mail() 沒轉,mail() 也沒轉 ,底層的 因為不知道編碼是什麼,當然也不能亂轉,於是就... XD

找了一下,在 解决WP邮件通知在gmail中的标题乱码 這篇給了幾個方法,其中不需要額外的 library 大概就是在 pluggable-functions.php 內的 wp_mail() 最後面 return 的地方改成:

return @mail($to, "=?UTF-8?B?" . base64_encode($subject) . "?=", $message, $headers);

我把他改成:

return @mail($to, "=?" . get_settings('blog_charset') . "?B?" . base64_encode($subject) . "?=", $message, $headers);

這樣就 okay 了 :p

PS:其實我不確定能不能 work XD 我是打算 post 一篇,然後測試一下看看標題正不正確 XD

Update:目前看起來跑得很好:

Update:我另外修改了 From: 的部分,這個部分也需要正確的 encoding,同樣一個檔案裡面,把:

$from = "From: \"$blogname\" <$wp_email>";

改成:

$from = "From: =?" . get_settings('blog_charset') . "?B?" . base64_encode("\"$blogname\"") . "?= <$wp_email>";

另外把:

$from = "From: \"$comment->comment_author\" <$wp_email>";

改成:

$from = "From: =?" . get_settings('blog_charset') . "?B?" . base64_encode("\"$comment->comment_author\"") . "?= <$wp_email>";

一樣,先測一陣子看看,沒問題就到 上送 ticket 請他們 patch。

13 thoughts on “WordPress 通知郵件標題的亂碼”

  1. 應該用正確的方法解決事情:WordPress 沒有依照 RFC 的規定送,就應該修改 WordPress 本身,而不是生一個 plugin「能用就好」。

  2. Pingback: Anonymous
  3. Pingback: 靜靜的部落

Leave a Reply

Your email address will not be published. Required fields are marked *