PHPMailer character encoding issues

前端 未结 9 1079
太阳男子
太阳男子 2020-12-07 07:38

I try to use PHPMailer to send registration, activation. etc mail to users:

require(\"class.phpmailer.php\");
$mail -> charSet = \"UTF-8\";
$mail = new PH         


        
9条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 08:05

    If you are 100% sure $message contain ISO-8859-1 you can use utf8_encode as David says. Otherwise use mb_detect_encoding and mb_convert_encoding on $message.

    Also take note that

    $mail -> charSet = "UTF-8"; 
    

    Should be replaced by:

    $mail->CharSet = 'UTF-8';
    

    And placed after the instantiation of the class (after the new). The properties are case sensitive! See the PHPMailer doc fot the list & exact spelling.

    Also the default encoding of PHPMailer is 8bit which can be problematic with UTF-8 data. To fix this you can do:

    $mail->Encoding = 'base64';
    

    Take note that 'quoted-printable' would probably work too in these cases (and maybe even 'binary'). For more details you can read RFC1341 - Content-Transfer-Encoding Header Field.

提交回复
热议问题