PHP 方法 imap_search 按日期
我试图仅显示过去 5 分钟内收到的电子邮件,例如:
$since = date('d-M-Y G\:i', time() - 300); // current time - 5 min
$mb = imap_search ($m_mail, 'UNSEEN SINCE ' . $since . '');
有没有简单的方法可以做到这一点?我找到了一种方法:获取当天所有未见过的邮件(例如:2010 年 5 月 9 日),循环浏览这些电子邮件,然后检查在过去 X 分钟内是否发送了任何邮件。如果是这样,则回显它(使用 imap_headerinfo->udate )。
但是,当我查看 gmail.com 时,我们在 17:08 收到了一封电子邮件,而在我的服务器上,该电子邮件似乎是在 14:08 收到的。
更新:我解决了问题,它显示电子邮件是在 17:08 发送的: gmail.com 和我的应用程序中的 04 显示为 14:04。我将全球服务器时区更改为 GMT +0 并设置应用程序时区。现在它显示了正确的时间,但我仍然不知道如何以更短的方式获取过去 X 时间内收到的电子邮件。
I'm trying to show only the emails received in the last 5 min for example:
$since = date('d-M-Y G\:i', time() - 300); // current time - 5 min
$mb = imap_search ($m_mail, 'UNSEEN SINCE ' . $since . '');
Is there an easy way to do this? I found a way: take all the unseen mails for the current day (ex:9 may 2010), loop through these emails and then check if any were sent in the last X minutes. If so echo it ( using the imap_headerinfo->udate ).
However, when I looked at gmail.com one email was received at 17:08 and on my server it appears that the email was received at 14:08
UPDATE: I resolved the problem where it showed me that the email was sent at 17:04 in gmail.com and in my application showed 14:04. I changed the global server timezone to GMT +0 and set the application timezone. Now it shows me the time correctly but still I don't know how to get the emails received in the last X amount of time in a shorter way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于 PHP 使用 IMAP2 搜索工具,不允许按时间搜索,这可能是唯一的解决方案。或者您可以查看“最近”标志,但这仍然需要循环遍历当天的所有消息。
As PHP uses IMAP2 search facilities which don't allow searching by time, this probably is the only solution. Or you could look at RECENT flag, but that still requires looping through all messages of the day.
我使用上面的搜索:
I Use search above: