找回密碼
 註冊
搜索
查看: 1948|回復: 0

[教學] 解決php中用mail發郵件時標題出現亂碼

[複製鏈接]
發表於 2010-1-19 18:44:48 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
php程序使用mail()函數發送郵件的時候,標題中文的話會出現亂碼。
解決方法:
先用函數base64_encode() — 使用 MIME base64 對數據進行編碼
標題字符串前加編碼類型例如: =?UTF-8?B?
標題字符串後加:?=
郵件header說明Content-type — 防止郵件正文也亂碼
    $to         = "xinple@example.com";
  • $subject  = "=?UTF-8?B?".base64_encode("郵件標題")."?=";
  • $headers  = "MIME-Version: 1.0" . "\r\n";
  • $headers .= "Content-type: text/html; charset=utf-8" . "\r\n";
  • // Additional headers
  • $headers .= "To: Xinple <xinple@example.com>". "\r\n";
  • $headers .= "From: Admin <admin@example.com>" . "\r\n";
  • $headers .= "Reply-To: Xinple <xinple@example>" . "\r\n";
  • mail($to, $subject, $message, $headers);
 
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|小黑屋|TShopping

GMT+8, 2025-5-1 03:56 , Processed in 0.020075 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回復 返回頂部 返回列表