PHP IMAP: Using UID to get header info

Interesting that imap_headerinfo() does not allow a UID for the $msg_number field like all other fetching functions seem to allow.

If you want to use a UID to fetch the headers, use this two-step process:

* assumes $mbox is your stream, and $uid is set
* properly. Proper error checking is up to you.
$hText = imap_fetchbody($mbox, $uid, '0', FT_UID);
$headers = imap_rfc822_parse_headers($hText);

The result is the same as the output of imap_headerinfo(), but you get to use the UID.


Leave a Reply