简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM