Finding messages in the mailbox

suggest change

You can return a list of all the messages in a mailbox using imap_headers.

<?php
$headers = imap_headers($mailbox);

The result is an array of strings with the following pattern:

[FLAGS] [message number])[DD-Mon-YYYY] [FROM ADDRESS] [SUBJECT TRUNCATED TO 25 CHAR] ([SIZE] chars)

Here’s a sample of what each line could look like:

A     1)19-Aug-2016 someone@example.com Message Subject (1728 chars)
D     2)19-Aug-2016 someone@example.com RE: Message Subject (22840 chars)
U     3)19-Aug-2016 someone@example.com RE: RE: Message Subject (1876 chars)
N     4)19-Aug-2016 someone@example.com RE: RE: RE: Message Subje (1741 chars)
Symbol Flag Meaning
A Answered Message has been replied to
D Deleted Message is marked deleted, but not yet expunged
F Flagged Message is flagged or starred for attention
N New Message is recent and has not been seen
R Recent Message arrived in the current session
U Unread Message has not been seen, and it is not recent
X Draft Message is a draft

Note that this call could take a fair amount of time to run and may return a very large list.

imap_headers() returns false on failure. An alternative is to load one message at a time. Sequence numbers run from 1 through imap_num_msg($mailbox). Number 1 is the first message in the current mailbox order, which is often the oldest.

imap_headerinfo() (alias imap_header()) returns the header as an object:

<?php
$header = imap_headerinfo($mailbox , 1);


stdClass Object
(
    [date] => Wed, 19 Oct 2011 17:34:52 +0000
    [subject] => Message Subject
    [message_id] => <04b80ceedac8e74$51a8d50dd$0206600a@user1687763490>
    [references] => <ec129beef8a113c941ad68bdaae9@example.com>
    [toaddress] => Some One Else <someoneelse@example.com>
    [to] => Array
        (
            [0] => stdClass Object
                (
                    [personal] => Some One Else
                    [mailbox] => someonelse
                    [host] => example.com
                )
        )
    [fromaddress] => Some One <someone@example.com>
    [from] => Array
        (
            [0] => stdClass Object
                (
                    [personal] => Some One
                    [mailbox] => someone
                    [host] => example.com
                )
        )
    [reply_toaddress] => Some One <someone@example.com>
    [reply_to] => Array
        (
            [0] => stdClass Object
                (
                    [personal] => Some One
                    [mailbox] => someone
                    [host] => example.com
                )
        )
    [senderaddress] => Some One <someone@example.com>
    [sender] => Array
        (
            [0] => stdClass Object
                (
                    [personal] => Some One
                    [mailbox] => someone
                    [host] => example.com
                )
        )
    [Recent] =>  
    [Unseen] =>  
    [Flagged] =>  
    [Answered] =>  
    [Deleted] =>  
    [Draft] =>  
    [Msgno] =>    1
    [MailDate] => 19-Oct-2011 17:34:48 +0000
    [Size] => 1728
    [udate] => 1319038488
)

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents