發表文章

目前顯示的是有「utf8」標籤的文章

PHP發email信件 mail 函數標題編碼問題

用PHP mail函數 發信使用unicode,在某些收信軟體會出現標題問號?的問題,可用base64_encode函數來解決: 如果 $to = 'goal@test.com'; $subject = 'test subject encode'; $mailmsg = 'test centent encode'; $header = 'Content-type: text/html; charset=UTF-8; Content-Transfer-Encoding'; $para = '-f'.'test@test.com'; mail($to,subject,$mailmsg,$header,$para); 寄出後,若於MS Outlook等收信軟體或App遇到標題 ????? 等字串,則可利用以下方式修正: function StringEncode($code,$string) {   $encodestring = "=?$code?B?".base64_encode($string)."?=" ;  /* 透過base64來預編UTF-8 碼 ,除標題亦可用在寄件者與收件者名稱,如:收件者<goal@test.com> */   return $encodestring;   } $to = 'goal@test.com';  $subject = StringEncode('UTF-8','test subject encode'); $mailmsg = 'test centent encode'; $header = 'Content-type: text/html; charset=UTF-8'; $para = '-f'.'test@test.com'; mail($to,subject,$mailmsg,$header,$para); 參考資料 https://stackoverflow.com/questions/454833/sy...