我使用 php imap 函數(shù)連接并從 Gmail 帳戶獲取電子郵件,它工作正常,但現(xiàn)在,由于他們更新的政策,即使登錄憑據(jù)正確,我也會(huì)收到以下錯(cuò)誤
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
我認(rèn)為這是因?yàn)樗麄兏铝苏摺S惺裁崔k法可以做到這一點(diǎn)嗎?
這些是連接到帳戶的當(dāng)前代碼
$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);
無(wú)法使用兩步身份驗(yàn)證的應(yīng)用程序需要使用應(yīng)用程序密碼(而不是默認(rèn)帳戶密碼)登錄 Gmail。
有關(guān)在 Gmail 帳戶中設(shè)置應(yīng)用程序密碼的詳細(xì)信息,請(qǐng)?jiān)L問 https://support.google.com/accounts/answer/185833?sjid=6399608693125087466-EU 和其他地方。