PHP 方法 imap_search 按日期

发布于 2024-09-01 01:14:39 字数 553 浏览 10 评论 0原文

我试图仅显示过去 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

摇划花蜜的午后 2024-09-08 01:14:39

由于 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.

童话里做英雄 2024-09-08 01:14:39

我使用上面的搜索:

$mailbox = imap_open($str_conexao, $login, $senha) or die("Can't connect: " . imap_last_error());

echo $since = date("D, d M Y", strtotime("-1 days"));

$search = imap_search($mailbox, 'FROM "[email protected]" SINCE "'.$since.' 00:00:00 -0700 (PDT)"', SE_UID);
echo "<PRE>";
  var_dump($search);
echo "</PRE>";
foreach ($search as $msg_id)
{
    //Pega informações da mensagem
    $overview = imap_fetch_overview($mailbox, $msg_id, FT_UID);
    echo "<PRE>";
     var_dump($overview);
    echo "</PRE>";
}

I Use search above:

$mailbox = imap_open($str_conexao, $login, $senha) or die("Can't connect: " . imap_last_error());

echo $since = date("D, d M Y", strtotime("-1 days"));

$search = imap_search($mailbox, 'FROM "[email protected]" SINCE "'.$since.' 00:00:00 -0700 (PDT)"', SE_UID);
echo "<PRE>";
  var_dump($search);
echo "</PRE>";
foreach ($search as $msg_id)
{
    //Pega informações da mensagem
    $overview = imap_fetch_overview($mailbox, $msg_id, FT_UID);
    echo "<PRE>";
     var_dump($overview);
    echo "</PRE>";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文