John Davidson

php - PHPMailer fails using Office 365 SMTP

0 comments
Message:


I am using this code, which I've been using for a long time with a Linux server for mail but recently moved to Office 365 and have updated the credentials.


I also added $email->SMTPSecure = ''; for 365.


$email = new PHPMailer();
$email->SMTPDebug = 2;
$email->IsSMTP();
$email->SMTPAuth = true;
$email->IsHTML(true);
$email->Host = '';
$email->Port = 587;
$email->Username = '';
$email->Password = '';

But I'm getting an error


SMTP -> FROM SERVER:220 LO2P265CA0058.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sun, 3 Oct 2021 12:18:59 +0000
SMTP -> FROM SERVER: 250-LO2P265CA0058.outlook.office365.com Hello [***] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 SMTPUTF8
SMTP -> ERROR: AUTH not accepted from server: 504 5.7.4 Unrecognized authentication type [LO2P265CA0058.GBRP265.PROD.OUTLOOK.COM]
SMTP -> FROM SERVER:221 2.0.0 Service closing transmission channel
SMTP Connect() failed.

I used this tool to test the settings, and it works fine https://www.gmass.co/smtp-test



My Answer:
It looks like the issue might be with the authentication type that Office 365 is expecting. Instead of setting `$email->SMTPSecure = '';`, try setting it to `tls` like this:

php
$email->SMTPSecure = 'tls';


This should tell PHPMailer to use TLS encryption for the SMTP connection, which is typically required for Office 365 SMTP servers.

Additionally, make sure that you are using the correct Office 365 SMTP server address in the `$email->Host` field and that the username and password you are using are correct.

If you continue to experience issues, you may want to reach out to your Office 365 administrator or support for further assistance.

Rate this post

4 of 5 based on 4447 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us