Authenticating with an Office 365 mailbox using phpmailer

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:


>WordPress: 4.9.5

>WordPress MS: No

>PHP: 5.6.35

>WP Mail SMTP: 1.2.5



>Mailer: smtp

>Constants: No

>ErrorInfo: SMTP connect() failed. >


>Port: 587

>SMTPSecure: tls

>SMTPAutoTLS: bool(true)

>SMTPAuth: bool(true)



>OpenSSL: Yes

>SMTP Debug:

>2018-04-09 12:48:26 Connection: opening to, timeout=300, options=array (

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

>2018-04-09 12:48:26 SERVER -> CLIENT: 220-> 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

>2018-04-09 12:48:26 SERVER -> CLIENT: Hello [IP redacted]

>250-SIZE 52428800





>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 closing connection

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

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