Authenticating with an Office 365 mailbox using phpmailer

Highlighted
Occasional Visitor

I need to authenticate a 365 mailbox with our website using phpmailer, this doesn't work no matter the settings, tennant or account status (admin etc) and O365 support can provide no clear or helpful path to resolving the issue. Using any other email account works perfectly.

 

I've tried a variety of different port/encryption setups, the account credentials are correct, the mailbox in question is a full tenant admin etc. The results all fail for slightly different reasons.

 

I've encountered this issue before and received similarly unhelpful responses from support - the last time I ended up setting up a mail account specifically for the website on an alternative domain.

Has anyone encountered something similar?

 

Debug Output:

 

>There was a problem while sending a test email. Related debugging output is shown below:

>Versions:

>WordPress: 4.9.5

>WordPress MS: No

>PHP: 5.6.35

>WP Mail SMTP: 1.2.5

 

>Params:

>Mailer: smtp

>Constants: No

>ErrorInfo: SMTP connect() failed. >https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

>Host: smtp.office365.com

>Port: 587

>SMTPSecure: tls

>SMTPAutoTLS: bool(true)

>SMTPAuth: bool(true)

 

>Server:

>OpenSSL: Yes

>SMTP Debug:

>2018-04-09 12:48:26 Connection: opening to smtp.office365.com:587, timeout=300, options=array (
)

>2018-04-09 12:48:26 Connection: opened

>2018-04-09 12:48:26 SERVER -> CLIENT: 220->sisko.sever.com ESMTP Exim 4.89_1 #1 Mon, 09 Apr 2018

>13:48:26 +0100 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.

>2018-04-09 12:48:26 CLIENT -> SERVER: EHLO www.website.com

>2018-04-09 12:48:26 SERVER -> CLIENT: 250-sisko.server.com Hello www.website.com [IP redacted]

>250-SIZE 52428800

>250-8BITMIME

>250-PIPELINING

>250-AUTH PLAIN LOGIN

>250-STARTTLS

>250 HELP

>2018-04-09 12:48:26 CLIENT -> SERVER: STARTTLS

>2018-04-09 12:48:26 SERVER -> CLIENT: 220 TLS go ahead

>2018-04-09 12:48:26 SMTP Error: Could not connect to SMTP host.

>2018-04-09 12:48:26 CLIENT -> SERVER: QUIT

>2018-04-09 12:48:26 SERVER -> CLIENT: 221 sisko.server.com closing connection

>2018-04-09 12:48:26 Connection: closed

>2018-04-09 12:48:26 SMTP connect() failed.

>https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting