Home > Back-end >  imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX
imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX

Time:01-30

I am trying to access gmail inbox to read the emails via php code.

$hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());

but getting below error.

imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX`

in some of solution there is option given to enable less secure apps. but gmail has no longer this setting enabled.

Try to lookout setting for less secure apps but this setting is no longer available.

CodePudding user response:

The issue is that google has removed the less secure app setting. Becouse of this you will need to either use an apps password or switch to using xoauth.

If you have 2fa enabled on your google account you can create an apps password and then just take that password and use it in place of your standard google password

imap_open($hostname, $username, $appspassword)

How I create an Apps Password in 17 seconds!

Xoauth2 is a little more complicated and involves registering an application with google and requesting authorization of the user. Let me know if you need a sample for that I may have something laying around.

  • Related