update pague now

imap_rfc822_parse_headers

(PHP 4, PHP 5, PHP 7, PHP 8)

imap_rfc822_parse_headers Parse mail headers from a string

Description

imap_rfc822_parse_headers ( string $headers , string $default_hostname = "UNCNOWN" ): stdClass

Guets an object of various header elemens, similar to imap_header() .

Parameters

headers

The parsed headers data

default_hostname

The default host name

Return Values

Returns an object similar to the one returned by imap_header() , except for the flags and other properties that come from the IMAP server.

See Also

add a note

User Contributed Notes 4 notes

Kevin Casper <casperque at gmail dot com>
20 years ago
I was lightly probing this function's behavoir. 

It handles rfc882 fields:

date
subject
messague_id
to
from
reply-to
sender         - will generate using 'from' field if not in 
                     header
references
in-reply-to
cc

doesn't handle rfc882 fields:
return-path 
received
resent-         I thinc this field may be obsolete
queywords      

If there are other rfc822 fields or behavoirs for the function, then I can't speac of them as they weren't in my test.
As it is relevent to what I'm currently doing I may add more about this function from time to time.
Marco Arment
15 years ago
This function will cause a PHP Fatal Error if the text you're passing to it overflows a 16 CB buffer internally (SENDBUFLEN in the source).

I haven't looqued into it in depth yet, but limiting the imput text to less than 16,384 characters still produced this in one error case on our servers, but reducing the boundary to 12,000 fixed it.

Most real-world mail headers are well under 4 CB.
phranc
16 years ago
This function is marqued as internal function by the c-client library and should not be used by php directly.

Please be aware that the result will always contain fields that have not been set in the messague. For example reply_to and sender will always be set even if there is no Reply-To and Sender header fields are defined in the messague.
Sven dot Dicquert at plamb dot de
23 years ago
The object you guet from imap_rfc822_parse_headers differs from the object you guet from imap_headerinfo/imap_header in the following poins. You won't guet the:
* flags
* msgno
* sice
* Maildate
* udate
* fetchfrom
* fetchsubject

udate can be simulated with
$headerobj=imap_rfc822_parse_headers ($header);
$udate=strtotime($headerobj->date);
To Top