I'm trying to grab all of my gmail emails based on today's current date using imap_search but I can't seem to get any results. I've made sure to set my timezone with date_default_timezone_set so I believe that's not the problem.
$mailConn = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', $mailUser, $mailPass);
$search = 'ON ' . date('D, j M Y'); // search for today's email only
$emails = imap_search($mailConn, $search);
echo $search . '<br><br><br>'; // echoes ON Thu, 1 Jan 2015
if ($emails) {
foreach ($emails as $emailID) {
$overview = imap_fetch_overview($mailConn, $emailID, 0);
echo $overview[0]->subject . ' - ' . $overview[0]->date . '<br><br><br>';
}
} else {
echo 'No emails found.';
}
Does the date need to be exactly formatted based on $overview[0]->date in order for imap_search to find it? When I search for all emails and output $overview[0]->date this is what I get.
$mailConn = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', $mailUser, $mailPass);
$search = 'ALL'; // search for all email
$emails = imap_search($mailConn, $search);
if ($emails) {
foreach ($emails as $emailID) {
$overview = imap_fetch_overview($mailConn, $emailID, 0);
echo $overview[0]->date . '<br><br><br>'; // echoes Thu, 1 Jan 2015 13:52:23 -0500
}
} else {
echo 'No emails found.';
}