When my mail account has some messages matching the search criteria it gives the correct count. But whenever there is no messages(0 number of messages) as per the searching criteria that time also it returns the count as '1'..here is my code..Give me suggestions..
$imap = imap_open("{mail.amazepixels.com}INBOX", "mail_id", "password")
or die("can't connect: " . imap_last_error());
$rec = imap_search($imap, 'ON "22 May 2017"');
$rec_count = count($rec);
$ans = imap_search($imap, 'UNANSWERED ON "22 May 2017"');
$ans_count = count($ans);
$seen = imap_search($imap, 'UNSEEN ON "22 May 2017"');
$seen_count = count($seen);
echo $rec_count."-".$ans_count."-".$seen_count;exit;
I just have given the future date..it returns the count 1
always..
imap_search()
returns false
if no messages are found and count(false) == 1
.
You can fix it by changing it to:
$ans_count = $ans ? count($ans) : 0;
From the manual:
Return FALSE if it does not understand the search criteria or no messages have been found.
Here's a post about the count issue: Why count(false) return 1?