Time Zone issue in IMAP

945 Views Asked by At

I am fetching emails from Gmail. when i searched latest emails from Gmail using PHP Imap after a date time It is giving me repeated result or not accurate.

Code sample which i am using to get next latest messages after a date time. I know these are Time Zones issue. I am storing messages in my DB.

How to get rid from These time zones issue?

if($lastMsgTimeDate == '') {
 $date = date("j F Y H:i:s");
}else{
 $date = date("j F Y H:i:s", strtotime($lastMsgTimeDate));
}

$emails = imap_search($inbox,'since "'.$date.'"' ); 
1

There are 1 best solutions below

1
On

As PHP uses IMAP2 search facilities which don't allow searching by time, this probably this could be your timezone issue solved.

Make use of last UID rather than date.

Search all recent messages and if it gets to the last UID then Exit the search