PHP 寄信使用UTF-8編碼

我做的某某x網~~~~~~~

說在結帳的時候~~~~要寄一封確認信件給對方

然後我就用mail的函式去寄信~~~~

一直寄到有亂碼~~~~~~我上網找好多header的編輯~~~設定他的編碼等等

就是搞不定~~~~~~~~

最好找到這玩意~~~~~一用就出來了~~~~酷斃了XD

function UTF8_mail($from,$to,$subject,$message,$cc="",$bcc="")
{
$from = explode("<",$from );

$headers =
"From: =?UTF-8?B?"
.base64_encode($from[0])."?= <"
. $from[1] . "\r\n";

$to = explode("<",$to );
$to = "=?UTF-8?B?".base64_encode($to[0])
."?= <". $to[1] ;

$subject="=?UTF-8?B?"
.base64_encode($subject)."?=\n";

if($cc!=""){
$cc = explode("<",$cc );
$headers .= "Cc: =?UTF-8?B?"
.base64_encode($cc[0])."?= <"
. $cc[1] . "\r\n";
}

if($bcc!=""){
$bcc = explode("<",$bcc );
$headers .= "Bcc: =?UTF-8?B?"
.base64_encode($bcc[0])."?= <"
. $bcc[1] . "\r\n";
}

$headers .=
"Content-Type: text/html; "
. "charset=UTF-8; format=flowed\n"
. "MIME-Version: 1.0\n"
. "Content-Transfer-Encoding: 8bit\n"
. "X-Mailer: PHP\n";

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

}

UTF8_mail(
"我是標題跟寄件者 ",
"我是要寄給人的信箱 ",
"我是標題",
"我是信件內容",
"",
""
);


資料來源http://geoland.org/2007/12/utf8-ready-php-mail-function/

沒有留言: