我尝试使用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->FromName = utf8_decode($_POST['name']);

http://php.net/manual/en/function.utf8-decode.php

其他回答

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

为了避免使用PHPMailer类发送邮件时的字符编码问题,我们可以使用“CharSet”参数将其配置为使用UTF-8字符编码发送邮件,如下面的Php代码所示:

$mail = new PHPMailer();
$mail->From = 'midireccion@email.com';
$mail->FromName = 'Mi nombre';
$mail->AddAddress('emaildestino@email.com');
$mail->Subject = 'Prueba';
$mail->Body = '';
$mail->IsHTML(true);


// Active condition utf-8
$mail->CharSet = 'UTF-8';


// Send mail
$mail->Send();

我自己就是这样工作的

  $mail->FromName = utf8_decode($_POST['name']);

http://php.net/manual/en/function.utf8-decode.php

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

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

应替换为:

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

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

$mail->addCustomHeader('Content-Type', 'text/plain;charset=utf-8');
$mail->Subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';;