欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

phpmailer发邮件中文乱码问题如何解决

程序员文章站 2022-04-07 22:10:50
...
在用phpmailer发送中文内容的邮件时,经常出现乱码,本文给出一个例子,主要是加上了编码设置base64,可以解决乱码的问题,供大家参考。 使用PHPMailer类发送邮件,

代码如下:

IsSMTP();
 $mail->CharSet = "GB2312";                     //chinese;
 $mail->Encoding = "base64";
 $mail->SMTPAuth   = true;
 $mail->SMTPSecure = "ssl";
 $mail->Host       = " smtp ";                  // set smtp server domain or ip;
 $mail->Port       = 465;
 $mail->Username   = " login account ";        // login account;
 $mail->Password   = " login password ";       // login password
 $mail->From       = " login account ";        // login account;
 $mail->FromName   = "sender name";            // sender name;
 $mail->Subject    = "$subject";
 $mail->Body       = "$content";
 $mail->AltBody    = "$content";
 $mail->WordWrap   = 50000;
 $mail->AddAddress($to,$receive_name);
 $mail->AddReplyTo("$reply_to","");             // reply to whom;
 $mail->AddAttachment("/path/to/file.zip");
 $mail->AddAttachment("/path/to/image.jpg", "new.jpg");
 $mail->IsHTML(true);
 
 if(!$mail->Send())
 {
  $send_result=$mail->ErrorInfo;  
 }
 else
 {
  $time=time();
  $time=date("Y-m-d H:i:s A");
  $send_result="Email sent to $to, at $time, Success";  
 } 
 return($send_result);
}

/*
the following code is a simple;
*/
$reply_to='sender@jbxue.com';
$to='customer@jbxue.com';
$receive_name='Carson';
$subject='程序员之家_bbs.it-home.org -欢迎大家的光临!';
$content='

this is a test.
last one

'; $send_email=send_email($mail,$reply_to,$to,$receive_name,$subject,$content); echo $send_email; ?>

附:PHPMailer邮件发送类V5.1下载地址