PHP Displaying unread mail count

前端 未结 2 526
广开言路
广开言路 2020-12-05 17:11

I am using php imap class. In my box I have a lot of mail, but with this script I would retrieve only the unreaded mail. How can I do it?

if ($mbox=imap_open         


        
2条回答
  •  春和景丽
    2020-12-05 17:29

    There is two way you can follow:

    1. Looping through the messages

    $count = imap_num_msg($connection);
    for($msgno = 1; $msgno <= $count; $msgno++) {
    
        $headers = imap_headerinfo($connection, $msgno);
        if($headers->Unseen == 'U') {
           ... do something ... 
        }
    
    }
    

    2. Using imap_search

    There's a flag called UNSEEN which you can use to search for the unread emails. You would call the imap_search function with the UNSEEN flag like so:

    $result = imap_search($connection, 'UNSEEN');
    

    If you need to combine this with more search flags, for example searching for messages from me@example.com, you could do this:

    $result = imap_search($connection, 'UNSEEN FROM "me@example.com"');
    

    For a complete list of the available flags, refer to the criteria section of the imap_search manual page on the PHP website (www.php.net/imap_search)

    Source: http://www.electrictoolbox.com/php-imap-unread-messages/

提交回复
热议问题