为什么用phpmailer发送邮件时乱码

在使用phpmailer发送html格式电子邮件时,我们需要指定文件编码

这里贴一个函数

function phpmailer_send_site_mail( $to , $from , $subject , $content )
{
 if( !isset( $GLOBALS[’__phpmailer’] ) )
 {
  include( ROOT . ‘lib/phpmailer.class.php’ );
  $GLOBALS[’__phpmailer’] = new PHPMailer();
 }

 $mail = $GLOBALS[’__phpmailer’];

 $mail->From = $from ;
 $mail->FromName =  ‘WEB_SITE_NAME’ ;
 $mail->CharSet = "utf-8"; // 这里指定字符集!
 $mail->Encoding = "base64";
 $mail->AddAddress( $to );
 
 $mail->AddReplyTo(  ‘WEB_SITE_EMAIL’ , ‘WEB_SITE_NAME’);
 
 $mail->WordWrap = 50; // set word wrap
 $mail->IsHTML(true); // send as HTML
 
 $mail->Subject = $subject;
 $mail->Body = $content;(www.iocblog.net 文章来源)
 return $mail->Send();

}

但是请注意,这并不能完全保证你收到的邮件是正确的编码

在发送html邮件时 我们需要发送一个完整的html文档 就算你只发送 中文 两个字,也需要发送如下html

<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
中文
</body>
</html>

才能保证在邮件里边看到正确的文字。(www.iocblog.net 文章来源)

PS:感谢vicki同学指出问题所在。

论坛讨论:
http://www.phpmore.com/bbs/viewthread.php?tid=22&extra=page%3D1

关于phpmailer,请查看more上边的详细介绍
http://www.phpmore.com/?u=tech_display&id=2




文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。