0
votes

I am trying to connect to Office 365 using PHP Imap but it won't connect with Office 365. Everything works fine for gmail and other email hosts but on Office 365 I get a can not authenticate (I am sure the email and password are correct).

Server has an SSL certificate and IP Address has been whitelisted in Office. I am thinking it is something to do with the hostname.

This is what I am currently trying:

{outlook.office365.com:993/imap/ssl}

Also tried:

{outlook.office365.com:993/imap/ssl/novalidate-cert}

And

{outlook.office365.com:993/ssl}

UPDATE It looks like this may be because this is a shared account based on the screenshot. Would this change my hostname?

enter image description here

2
If the account has two-step authentication, you will need to generate an application specific password.Max
Thanks @Max it does not have two-step authentication enabled.Derek
Reviewed this answer based on my findings but I still get Authentication error: stackoverflow.com/questions/28481028/…Derek

2 Answers

2
votes

Please try use the /authuser method.

imap_open("{outlook.office365.com:993/imap/ssl/[email protected]}", "[email protected]", "password");
1
votes

If certificates are not to be validated, use the "novalidate-cert" in the connection

 imap_open("{outlook.office365.com:993/imap/ssl/novalidate-cert/authuser=$user/user=$user}", $user, $pass);

this should work