我尝试使用PHPMailer发送注册,激活。等邮件给用户:

require("class.phpmailer.php");
$mail -> charSet = "UTF-8";
$mail = new PHPMailer();
$mail->IsSMTP();  
$mail->Host     = "smtp.mydomain.org";  
$mail->From     = "name@mydomain.org";
$mail->SMTPAuth = true; 
$mail->Username ="username"; 
$mail->Password="passw"; 
//$mail->FromName = $header;
$mail->FromName = mb_convert_encoding($header, "UTF-8", "auto");
$mail->AddAddress($emladd);
$mail->AddAddress("mytest@gmail.com");
$mail->AddBCC('mytest2@mydomain.org', 'firstadd');
$mail->Subject  = $sub;
$mail->Body = $message;
$mail->WordWrap = 50;  
if(!$mail->Send()) {  
   echo 'Message was not sent.';  
   echo 'Mailer error: ' . $mail->ErrorInfo;  
}

$消息包含拉丁字符。不幸的是,所有的webmail (gmail, webmail.mydomain.org, emailaddress.domain.xx)都使用不同的编码。

如何强制使用UTF-8编码在所有邮箱上显示完全相同的邮件?

我尝试转换邮件头宽度mb_convert_encoding(),但没有运气。


当前回答

$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->Encoding = "16bit";

其他回答

我变得越来越……在$mail->主题/w PHPMailer。

所以对我来说,完整的解决方案是:

// Your Subject with tildes. Example.
$someSubjectWithTildes = 'Subscripción España';

$mailer->CharSet = 'UTF-8';
$mailer->Encoding = 'quoted-printable';
$mailer->Subject = html_entity_decode($someSubjectWithTildes);

希望能有所帮助。

抱歉我来晚了。根据您的服务器配置,您可能需要严格使用小写字母utf-8指定字符,否则它将被忽略。如果你在这里寻找解决方案,上面的答案都没有帮助,试试这个:

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

应替换为:

$mail->CharSet = "utf-8";
$mail -> CharSet = "UTF-8";
$mail = new PHPMailer();

line $mail -> CharSet = "UTF-8";必须在$mail = new phpailer()之后;

试试这个

$mail = new PHPMailer();
$mail->CharSet = "UTF-8";

当以上均无效时,邮件仍然看起来像ª× " ×•× " × × × " ×•× × ×©×œ:

$mail->addCustomHeader('Content-Type', 'text/plain;charset=utf-8');
$mail->Subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';;
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->Encoding = "16bit";