user633268
user633268

Reputation: 223

imap count emails from certain emails

as the title says i want to count how many emails i have got from a certain email.

$message_count = imap_num_msg($imap); 

this will not work as it counts all emails in the mail box. i want to make something that gives me emails from the filter email but if i have non it tells me it.

thanks in advance and i hope you can help.

Upvotes: 1

Views: 2067

Answers (2)

Meekohi
Meekohi

Reputation: 10892

imap_search confusingly returns false when there are no e-mails, and count(false)==1, so you actually need something like:

$response = imap_search($inbox,"FROM $sender");

$nEmails = 0;
if($response) {$nEmails  = count($response);}

Upvotes: 1

dkarp
dkarp

Reputation: 14763

imap_search will do a search on the currently-selected folder and return an array of matching messages. If you're looking to match messages by their "From" header, you'll search using the FROM criterion.

So the size of the returned array should work for you:

count(imap_search($imap, 'FROM "' . $email . '"'))

Upvotes: 2

Related Questions