SMTP OFFICE and PHPMAILER error : SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful

Damien Doumax 10 Reputation points
2023-06-05T16:02:17.3466667+00:00

Hello,

I'm trying to use Phpmailer on a web host, that use the SMTP from Office365

And i get an error SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful

It seems it's ok in the microsoft admin center (user account is authorized to use SMTP AUTH)

The Php Code is :

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require_once $_SERVER['DOCUMENT_ROOT'].'/secret/phpmailerjune203/autoload.php';	
$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      
    $mail->isSMTP();                                            
    $mail->Host       = 'smtp.office365.com';                    
    $mail->SMTPAuth   = true;                                   
    $mail->Username   = 'XXXXXXXXXXXX';    // Email account authorized in azure with SMTP AUTH                  
    $mail->Password   = 'XXXXXXXXXXXX';                             
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;        
    $mail->Port       = 587;                                    
	$mail->SMTPDebug  = 4;
	
    //Recipients
	$mail->setFrom('XXXXXXXXXXXXXXXX');
	$mail->addAddress('foo@bar.com');
	
    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $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}";
}

2023-06-05 15:51:47 Connection: opening to smtp.office365.com:587, timeout=300, options=array()
2023-06-05 15:51:47 Connection: opened
2023-06-05 15:51:47 SMTP INBOUND: "220 ZRAP278CA0003.outlook.office365.com Microsoft ESMTP MAIL Service ready at Mon, 5 Jun 2023 15:51:46 +0000"
2023-06-05 15:51:47 SERVER -> CLIENT: 220 ZRAP278CA0003.outlook.office365.com Microsoft ESMTP MAIL Service ready at Mon, 5 Jun 2023 15:51:46 +0000
2023-06-05 15:51:47 CLIENT -> SERVER: EHLO cse-alp.fr
2023-06-05 15:51:47 SMTP INBOUND: "250-ZRAP278CA0003.outlook.office365.com Hello [46.21.198.188]"
2023-06-05 15:51:47 SMTP INBOUND: "250-SIZE 157286400"
2023-06-05 15:51:47 SMTP INBOUND: "250-PIPELINING"
2023-06-05 15:51:47 SMTP INBOUND: "250-DSN"
2023-06-05 15:51:47 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2023-06-05 15:51:47 SMTP INBOUND: "250-STARTTLS"
2023-06-05 15:51:47 SMTP INBOUND: "250-8BITMIME"
2023-06-05 15:51:47 SMTP INBOUND: "250-BINARYMIME"
2023-06-05 15:51:47 SMTP INBOUND: "250-CHUNKING"
2023-06-05 15:51:47 SMTP INBOUND: "250 SMTPUTF8"
2023-06-05 15:51:47 SERVER -> CLIENT: 250-ZRAP278CA0003.outlook.office365.com Hello [46.21.198.188]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2023-06-05 15:51:47 CLIENT -> SERVER: STARTTLS
2023-06-05 15:51:47 SMTP INBOUND: "220 2.0.0 SMTP server ready"
2023-06-05 15:51:47 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2023-06-05 15:51:47 CLIENT -> SERVER: EHLO cse-alp.fr
2023-06-05 15:51:47 SMTP INBOUND: "250-ZRAP278CA0003.outlook.office365.com Hello [46.21.198.188]"
2023-06-05 15:51:47 SMTP INBOUND: "250-SIZE 157286400"
2023-06-05 15:51:47 SMTP INBOUND: "250-PIPELINING"
2023-06-05 15:51:47 SMTP INBOUND: "250-DSN"
2023-06-05 15:51:47 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2023-06-05 15:51:47 SMTP INBOUND: "250-AUTH LOGIN XOAUTH2"
2023-06-05 15:51:47 SMTP INBOUND: "250-8BITMIME"
2023-06-05 15:51:47 SMTP INBOUND: "250-BINARYMIME"
2023-06-05 15:51:47 SMTP INBOUND: "250-CHUNKING"
2023-06-05 15:51:47 SMTP INBOUND: "250 SMTPUTF8"
2023-06-05 15:51:47 SERVER -> CLIENT: 250-ZRAP278CA0003.outlook.office365.com Hello [46.21.198.188]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-AUTH LOGIN XOAUTH2250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2023-06-05 15:51:47 Auth method requested: UNSPECIFIED
2023-06-05 15:51:47 Auth methods available on the server: LOGIN,XOAUTH2
2023-06-05 15:51:47 Requested auth method not available:
2023-06-05 15:51:47 Auth method selected: LOGIN
2023-06-05 15:51:47 CLIENT -> SERVER: AUTH LOGIN
2023-06-05 15:51:47 SMTP INBOUND: "334 VXNlcm5hbWU6"
2023-06-05 15:51:47 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2023-06-05 15:51:47 CLIENT -> SERVER: aW5mb0Bjc2UtYWxwLmZy
2023-06-05 15:51:47 SMTP INBOUND: "334 UGFzc3dvcmQ6"
2023-06-05 15:51:47 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2023-06-05 15:51:47 CLIENT -> SERVER: XXXXXXXXXXXXXXXXXXXX (redacted base 64 Password)
2023-06-05 15:51:55 SMTP INBOUND: "535 5.7.3 Authentication unsuccessful [ZRAP278CA0003.CHEP278.PROD.OUTLOOK.COM 2023-06-05T15:51:55.198Z 08DB650F680DA44E]"
2023-06-05 15:51:55 SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful [ZRAP278CA0003.CHEP278.PROD.OUTLOOK.COM 2023-06-05T15:51:55.198Z 08DB650F680DA44E]
2023-06-05 15:51:55 SMTP ERROR: Password command failed: 535 5.7.3 Authentication unsuccessful [ZRAP278CA0003.CHEP278.PROD.OUTLOOK.COM 2023-06-05T15:51:55.198Z 08DB650F680DA44E]
SMTP Error: Could not authenticate.
2023-06-05 15:51:55 CLIENT -> SERVER: QUIT
2023-06-05 15:51:55 SMTP INBOUND: "221 2.0.0 Service closing transmission channel"
2023-06-05 15:51:55 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
2023-06-05 15:51:55 Connection: closed
SMTP Error: Could not authenticate.
Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.

Any help appreciated

Thanks in advance

Damien

Office
Office
A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.
1,760 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.