简体   繁体   中英

How to fetch the recent emails alone from GMail Mail Box using imap class in PHP?

I would like to fetch email messages from GMail using PHP's imap class.

I tried:

$val = date('Y-m-d H:i:s', 1337352811);
$recentMails = imap_search($this->imapInBox, 'SINCE $val', SE_UID);

This did't work.

I tried it with <SINCE "4 Jun 2012"> . This works.

But I have a problem in downloading attachments when I use this option, and also this will cause redundancy and fetch the same emails again and again. I need to use an accurate time a like Unix time stamp to fetch only the latest emails. How can I achieve that?

Take a look at this excerpt from the RFC:

  RECENT
     Messages that have the \Recent flag set.

  SINCE <date>
     Messages whose internal date (disregarding time and timezone)
     is within or later than the specified date.

You can only search based on the date, not any more granular than that.

What you CAN do however, is unset the Recent flag, and search for the date AND Recent flag.

Google "imap phph gmail" and you'll find lots of tutorials and code. For example: Retrieve Your Gmail Emails Using PHP and IMAP

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