Search code examples
phpemailimap

PHP Imap - Count Number of Emails From Today


I need to get the number of emails that are in a gmail inbox from todays date only.

So far I have used this to only get emails from todays date:

$todaysEmails = imap_search($mbox,'ON "'.$date.'"');

And I have tried combining it with this to count the number of emails:

$numEmails = imap_num_msg($todaysEmails);

However this returns an error:

PHP Warning: imap_num_msg() expects parameter 1 to be resource, boolean given in /var/www/html/getAttachment.php on line 7

How can I go about achieving this correctly?


Solution

  • Date must be formatted in this format: "13 Jun 2017"

    $date = date("j F Y");