PHPMailer错误需要Gmail身份验证

时间:2020-06-25 13:41:54

标签: phpmailer

如何修复PHPMailler错误需要Gmail身份验证。请帮帮我!

以下是我使用PHPMailler发送邮件但出现错误的代码。

Gmail配置

enter image description here

enter image description here

浏览器

2020-06-25 13:44:30 SERVER -> CLIENT: 530-5.7.0 Authentication Required. Learn more at530 5.7.0 https://support.google.com/mail/?p=WantAuthError q24sm19435975pgg.3 - gsmtp 2020-06-25 13:44:30 SMTP ERROR: MAIL FROM command failed: 530-5.7.0 Authentication Required. Learn more at530 5.7.0 https://support.google.com/mail/?p=WantAuthError q24sm19435975pgg.3 - gsmtp The following From address failed: alotechads@gmail.com : MAIL FROM command failed,Authentication Required. Learn more at https://support.google.com/mail/?p=WantAuthError q24sm19435975pgg.3 - gsmtp,530,5.7.0SMTP server error: MAIL FROM command failed Detail: Authentication Required. Learn more at https://support.google.com/mail/?p=WantAuthError q24sm19435975pgg.3 - gsmtp SMTP code: 530 Additional SMTP info: 5.7.0 Email send failed2020-06-25 13:44:30 CLIENT -> SERVER: QUIT

文件配置

<?php
namespace App\Classes;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;


    class Mail
    {
        protected $mail;
    
        public function __construct()
        {
            $this->mail = new PHPMailer;
            $this->setUp();
        }
    
        public function setUp()
        {
            $this->mail->isSMTP();
    //        $this->mail->Mailer = 'smtp';
            $this->SMTPAuth = true;
    //        $this->mail->SMTPSecure = 'tls';
            $this->mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
            $this->mail->Host = 'smtp.gmail.com';
            $this->mail->Port = '587';
    
            $environment = getenv('APP_ENV');
            if($environment === 'local'){$this->mail->SMTPDebug = 3;}
    
            //auth info
            $this->mail->Username = 'alotechads@gmail.com';
            $this->mail->Password = '123456789';
    
            $this->mail->isHTML(true);    // Set email format to HTML
            $this->mail->SingleTo = true; // send muiti user
    
            // send info
    
            $this->mail->From = getenv('ADMIN_EMAIL');
            $this->mail->FromName = getenv('ADMIN_EMAIL');
        }
    
        public function send($data)
        {
            $this->mail->addAddress($data['to'], $data['name']);
            $this->mail->Subject = $data['subject'];
            $this->mail->Body = make($data['view'], array('data' => $data['body']));
            $this->mail->send();
        }
    }

0 个答案:

没有答案