简体   繁体   English

如何使用PHP中的imap类从GMail邮箱中单独获取最近的电子邮件?

[英]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. 我想使用PHP的imap类从GMail提取电子邮件。

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"> . 我尝试了<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. 我需要使用准确的时间(例如Unix时间戳)来仅获取最新的电子邮件。 How can I achieve that? 我该如何实现?

Take a look at this excerpt from the RFC: 看一下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. 但是,您可以做的是取消“ Recent标志的设置,然后搜索日期和“ Recent标志。

Google "imap phph gmail" and you'll find lots of tutorials and code. Google“ imap phph gmail”,您会发现很多教程和代码。 For example: Retrieve Your Gmail Emails Using PHP and IMAP 例如: 使用PHP和IMAP检索Gmail电子邮件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM