Problem with php's imap_search function regarding time zones.
March 11, 2013 4:00 PM Subscribe
I'm trying to use the php imap_search function to collect all of the emails I receive from my business's fulfillment company on a given day. The problem is that I can't seem to get the SEARCH ON to return all of the emails in a day, instead it seems to return all of the emails in a day shifted a few hours.
Howdy,
The emails are all being sent from PA, I live in OH, and my hosting is based in CA.
I have a simple test script that looks like this:
date_default_timezone_set('America/Los_Angeles');
$mailbox = imap_open ("{SERVER}", "USERNAME", "PASSWORD");
$mail = imap_search($mailbox,'ON "10-Mar-2013"');
foreach($mail as $msg){
$this_header = imap_headerinfo($mailbox, $msg);
echo $this_header->Subject.' - '.$this_header->Date;
}
imap_close($mailbox);
But produces a result of:
New order in your Spreadshirt shop [us_US] - Sun, 10 Mar 2013 14:26:46 -0400
New order in your Spreadshirt shop [us_US] - Sun, 10 Mar 2013 15:44:47 -0400
New order in your Spreadshirt shop [us_US] - Sun, 10 Mar 2013 16:17:51 -0400
New Order in Your Spreadshop spreadshirt.com [us_US] - Sun, 10 Mar 2013 17:56:03 -0400
New Order in Your Spreadshop spreadshirt.com [us_US] - Sun, 10 Mar 2013 17:56:03 -0400
New order in your Spreadshirt shop [us_US] - Sun, 10 Mar 2013 18:06:08 -0400
New order in your Spreadshirt shop [us_US] - Sun, 10 Mar 2013 18:25:00 -0400
New order in your Spreadshirt shop [us_US] - Sun, 10 Mar 2013 19:10:37 -0400
New order in your Spreadshirt shop [us_US] - Sun, 10 Mar 2013 20:28:26 -0400
New order in your Spreadshirt shop [us_US] - Mon, 11 Mar 2013 00:20:50 -0400
New order in your Spreadshirt shop [us_US] - Mon, 11 Mar 2013 00:36:45 -0400
New order in your Spreadshirt shop [us_US] - Mon, 11 Mar 2013 01:43:02 -0400
New order in your Spreadshirt shop [us_US] - Mon, 11 Mar 2013 02:27:43 -0400
Which, as you can see, returns both e-mails from the 10th and the first 3 hours of the 11th.
I tried changing date_default_timezone_set('America/New_York'); to date_default_timezone_set('America/Los_Angeles'); to match up with my server host's location but it has no effect.
Any ideas of how to get the search function to only return results from the one day I choose?
Thanks.
posted by Jezztek to computers & internet (6 answers total)
posted by Jezztek at 4:01 PM on March 11