您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHPMailer邮件标题中文乱码的解决方法

2024/2/29 4:03:32发布15次查看
charset = utf-8; // 设置编码
$mail->issmtp(); // 设置使用smtp服务发送
$mail->host = smtp.mail.com; $mail->username = user; $mail->password = pass; $mail->smtpauth = true; $mail->from = $from;
$mail->fromname = $fromname; if ( is_array( $to ) ) {
foreach ( $to as $address ) { $mail->addaddress( $address ); } } else { $mail->addaddress( $to ); } $mail->subject = $subject;
$mail->body = $message; $mail->altbody = $message; $mail->ishtml( true ); return $mail->send();
}?>
复制代码
用以上的代码发送英文邮件没有问题,但发送中文邮件时标题会有乱码。
解决方法:需要对 class.phpmailer.php 做一些修改:
修改1,1137 行:function encodeheader ($str, $position = 'text') {
将函数增加一个参数:
function encodeheader ($str, $position = 'text', $pl = 0) { if ( $pl ) return =? . $this->charset . ?b? . base64_encode($str) . ?=;
复制代码
修改2,796 行:$result .= $this->headerline(subject, $this->encodeheader(trim($this->subject)));
将调用改为:
$result .= $this->headerline(subject, $this->encodeheader(trim($this->subject),'text', 1));
复制代码
即可解决中文标题乱码的问题。
附,phpmailer邮件发送类v5.1下载地址。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product