您好,欢迎访问代理记账网站
移动应用 微信公众号 联系我们

咨询热线 -

电话 15988168888

联系客服
  • 价格透明
  • 信息保密
  • 进度掌控
  • 售后无忧

PHPMailer中文乱码解决方案

适用于thinkphp6

主要就是要设置两个地方

$mail->CharSet = "UTF-8";
$mail->Subject = "=?UTF-8?B?".base64_encode($title)."?=";

全部代码

//邮件发送
if (!function_exists('sendmail')) {
    function sendmail($address, $title, $body)
    {
        $mail = new \PHPMailer\PHPMailer\PHPMailer(true);
        try {
            $mail->SMTPDebug = 0;
            $mail->isSMTP();
            $mail->CharSet = "UTF-8";                     //utf-8;
            $mail->Encoding = "base64";
            $mail->Host = env('mail.host');
            $mail->SMTPAuth = true;
            $mail->Username = env('mail.username');
            $mail->Password = env('mail.password');
            $mail->SMTPSecure = env('mail.encryption');
            $mail->Port = env('mail.port');

            //Recipients
            $mail->setFrom(env('mail.from_address'), env('mail.from_name'));
            $mail->addAddress($address);
            //Content
            $mail->isHTML(true);
            $mail->Subject = "=?UTF-8?B?".base64_encode($title)."?=";
            $mail->Body = $body;
            $mail->send();
            return true;

        } catch (Exception $e) {
            return $e;
        }
    }

}
[MAIL]
HOST = 
PORT = 
USERNAME = 
PASSWORD = 
ENCRYPTION = 
FROM_ADDRESS = 
FROM_NAME = 

分享:

低价透明

统一报价,无隐形消费

金牌服务

一对一专属顾问7*24小时金牌服务

信息保密

个人信息安全有保障

售后无忧

服务出问题客服经理全程跟进