PHP Mailer 标头编码问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24652828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Problems with PHP Mailer header encoding
提问by user3820171
<?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 = "[email protected]"; // GMAIL username
$mail->Password = "xxxxxxxxxxx"; // GMAIL password
$mail->SetFrom('[email protected]', 'First Last');
$mail->AddReplyTo("[email protected]","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 = "[email protected]";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
The email sending is ok but have a problems with the header.
电子邮件发送没问题,但标题有问题。
Subject : 'ทดสอบ
'
主题:' ทดสอบ
'
I will try with
- php mail special characters utf8
- use => $mail->Subject = "=?UTF-8?B?".base64_encode($subject)."?=";
我会尝试
- php 邮件特殊字符 utf8
- 使用 => $mail->Subject = "=?UTF-8?B?".base64_encode($subject)."?=";
But it does not work for me. How can I know what is the header coding and solve this to be right in my Thai langauge?
但它对我不起作用。我怎么知道标题编码是什么,并在我的泰语中解决这个问题?
回答by Anri
Use
用
$mail->CharSet = 'UTF-8';
instead of
代替
$mail->CharSet = "utf8";