-
-
/**
- * PHPMailer邮件发送
- * Edit bbs.it-home.org
- */
- function smtp_main_send( $to, $subject, $message, $from, $fromName )
- {
- $mail = new PHPMailer();
$mail->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下载地址。
|