I used the php imap function to connect and get the email from the Gmail account and it was working fine, but now, due to their updated policy, I am getting the following error even though the login credentials are correct
PHP Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/ssl/novalidate-cert}[Gmail]/All Mail in PHP Notice: Unknown: Retrying PLAIN authentication after [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0
I think this is because they updated their policy. Is there any way to do this?
These are the current codes connected to the account
$hostname = '{imap.gmail.com:993/ssl/novalidate-cert}[Gmail]/All Mail'; $imap = imap_open($hostname, $username, $password); $emails = imap_search($imap, 'ALL'); if($emails) echo count($emails);
Apps that cannot use two-step authentication need to use the application password (instead of the default account password) to log in to Gmail.
For more information about setting an application password in your Gmail account, please visit https://support.google.com/accounts/answer/185833?sjid=6399608693125087466-EU and elsewhere.