0

When I trying to send a email using PHP SMTP email server, following error has occurred. SMTP Error: Could not authenticate. Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.

try {
            //Server settings
            $mail->isSMTP();                                            //Send using SMTP
            $mail->Host       = 'smtp.gmail.com';                     //Set the SMTP server to send through
            $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
            $mail->Username   = 'xxxx@gmail.com';                     //SMTP username
            $mail->Password   = 'xxxxxxx';                               //SMTP password
            $mail->SMTPSecure = 'tls';         //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
            $mail->Port       = 587;                                    //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
        
            //Recipients
            $mail->setFrom('tawiqha@gmail.com', 'reset');
            $mail->addAddress($email);     //Add a recipient
            $mail->addReplyTo('no-replay@gmail.com', 'no-replay');
            
            
            //Content
            $mail->isHTML(true);                                  //Set email format to HTML
            $mail->Subject = 'اعادة تعيين كلمة السر';
            $mail->Body    = $message;
            $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
        
            $mail->send();
            echo 'Message has been sent';
        } catch (Exception $e) {
            echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
        }
saba
  • 1
  • Did you see this: https://stackoverflow.com/a/32401071/231316 – Chris Haas May 20 '21 at 22:11
  • 1
    Does this answer your question? ["SMTP Error: Could not authenticate" in PHPMailer](https://stackoverflow.com/questions/3949824/smtp-error-could-not-authenticate-in-phpmailer) – Tangentially Perpendicular May 20 '21 at 22:53
  • As well as having been answered here many times, this exact issue is covered in [the PHPMailer troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#gmail-oauth2-and-allow-less-secure-apps). – Synchro May 21 '21 at 07:16

0 Answers0