How to solve the problem of Chinese garbled characters in emails sent by phpmailer

WBOY
Release: 2016-07-25 08:59:50
Original
1198 people have browsed it
When using phpmailer to send emails with Chinese content, garbled characters often appear. This article gives an example, mainly by adding the encoding setting base64, which can solve the problem of garbled characters for your reference. Send emails using PHPMailer class,

The code is as follows:

<?php
/**
 * 解决phpmailer发邮件中文乱码
 * edit bbs.it-home.org
*/

set_time_limit(0);

include("class.phpmailer.php");
include("class.smtp.php");

$mail=new PHPMailer();

function send_email($mail,$reply_to,$to,$receive_name,$subject,$content)
{
 $mail->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='<h1><font color=#f00>this is a test.<br>last one</font></h1>';

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

Attachment: PHPMailer email sending class V5.1 download address



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!