'PHP - Office365 connecting with imap_open

thanks for the anticipated help.

Does anyone know the current state of php connecting to office365 using imap_open?

I have tried all the suggestions found on stack overflow and my current code is below. I simply cant seem to connect to office365 using imap_open, either straight connection failure or other erros below.

Does anyone have this working in 2022

I have tried the code below which results in the error below. I have also gone through the office365 admin panel and whitelisted my server IP, i have enabled SMTP auth and enabled IMAP on the account I'm connecting to.

$username = 'xxxxx';
$password = 'xxxxx';

$host = "{outlook.office365.com:993/imap/ssl/novalidate-cert}Inbox";
$mbox=imap_open($host,$username,$password, NULL, 1, 
                           array('DISABLE_AUTHENTICATOR' => 'PLAIN')) or 
                   die(var_dump(imap_errors()));

This gives me the current error of too many login failures, but this error changes bases on the settings i try above within imap_open so im not sure this is an actual true error code

Warning: imap_open(): Couldn't open stream {outlook.office365.com:993/imap/ssl/novalidate-cert}Inbox in imap.connect2.php on line 14 array(2) { [0]=> string(13) "LOGIN failed." [1]=> string(23) "Too many login failures" }

So if i change the code to something more simple without the DISABLE_AUTHENTICATOR additional, i still get an error. See code and error below

$mbox=imap_open($host,$username,$password) or 
                   die(var_dump(imap_errors()));

I get authenticate failed

Warning: imap_open(): Couldn't open stream {outlook.office365.com:993/imap/ssl/novalidate-cert}Inbox in /home/tnslive/domains/manage.tnslive.com/public_html/webmail/imap.connect2.php on line 13
array(3) { [0]=> string(56) "Retrying PLAIN authentication after AUTHENTICATE failed." [1]=> string(56) "Retrying PLAIN authentication after AUTHENTICATE failed." [2]=> string(57) "Can not authenticate to IMAP server: AUTHENTICATE failed." }

I've been trying this for a week and tried other slight alternatives with the domain used in the imap_open function for office365 .... im at a massive loss here and i've bought office365 for a lot of people and now we cant use our application with the primary email via our php software. Nightmare.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source