PHP Mailer 头部编码问题

7
    <?php
require_once('../class.phpmailer.php');
//include("../class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
iconv_set_encoding("internal_encoding", "UTF-8");

$mail             = new PHPMailer();
$mail->CharSet = "utf8";
/*
$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);
*/
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host       = "mail.app-cpr.com"; // SMTP server
//$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "tls";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 25;                   // set the SMTP port for the GMAIL server
$mail->Username   = "xxxxxxx@gmail.com";  // GMAIL username
$mail->Password   = "xxxxxxxxxxx";            // GMAIL password    
$mail->SetFrom('xxxxxxx@gmail.com', 'First Last');

$mail->AddReplyTo("xxxxxxx@gmail.com","First Last");

$mail->Subject    = "ทดสอบ";
/*
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
*/
$mail->MsgHTML("ทดสอบ");

$address = "xxxxxxx@gmail.com";
$mail->AddAddress($address, "John Doe");

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

?>

邮件发送没有问题,但是标题出现了问题。

主题: "&#3607;&#3604;&#3626;&#3629;&#3610;"

我尝试过以下方法:
- php邮件特殊字符utf8
- 使用 => $mail->Subject = "=?UTF-8?B?".base64_encode($subject)."?=";

但对我没有用。 我如何知道标题编码并解决这个问题以在我的泰语中正确显示?


1
尝试使用 $mail->CharSet = "UTF-8"; - Maciej Jaśniaczyk
1个回答

18

使用

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

取而代之

$mail->CharSet = "utf8";


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接