PHP method for imap_search by date
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开发者_StackOverflow 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.
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:
$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 "somebody@exemple.com" 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>";
}
精彩评论