英文:
Fetch mails from gmail account using php IMAP
问题
我曾经使用php imap函数连接并获取Gmail帐户的电子邮件,一切正常,但现在由于他们更新了政策,即使登录凭据正确,我也遇到了以下错误:
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
我认为这是因为他们更新了政策。有没有办法使这个工作?
这是当前连接到帐户的代码:
$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);
英文:
I was using the php imap function to connect and get the emails 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 it is because they are updated the policy. Is there any way to make this work?
These are the current code to connect 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);
答案1
得分: 1
以下是翻译好的部分:
无法使用两步验证的应用程序需要使用应用密码登录 Gmail,而不是默认的帐户密码。
有关在您的 Gmail 帐户中设置应用程序密码的更多信息,请参阅 https://support.google.com/accounts/answer/185833?sjid=6399608693125087466-EU 和其他地方。
英文:
Applications which can't use 2-factor authentication need to sign in to Gmail with an App Password, not the default account password.
More info on setting up a App Password within your Gmail account is available at https://support.google.com/accounts/answer/185833?sjid=6399608693125087466-EU and elsewhere.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论