简体   繁体   中英

Api for gmail not working in php

I am trying to fetch emails from gmail in php using imap but its not working on my site. how can i do this ? Here is my code

<?php
    $mailbox = imap_open("{imap.googlemail.com:993/ssl}INBOX", "mygmailid@gmail.com", "mygmailpassword");
    $mail = imap_search($mailbox, "ALL");
    $mail_headers = imap_headerinfo($mailbox, $mail[0]);
    $subject = $mail_headers->subject;
    $from = $mail_headers->fromaddress;
    imap_setflag_full($mailbox, $mail[0], "\\Seen \\Flagged");
    imap_close($mailbox);
?>

This seems to be a wider issue, but something similar was fixed for me. Try unlocking your account with below url. Once the account is unlocked, check if it works well.

https://accounts.google.com/DisplayUnlockCaptcha

Check this discussion as well

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