Specifications
$message[‘subject’] = $header->subject;
$message[‘fromaddress’] = $header->fromaddress;
$message[‘toaddress’] = $header->toaddress;
$message[‘ccaddress’] = $header->ccaddress;
$message[‘date’] = $header->date;
// note we can get more detailed information by using from and to
// rather than fromaddress and toaddress, but these are easier
imap_close($imap);
return $message;
}
Again we have used open_mailbox() to open the user’s mailbox.
This time, however, we are after a specific message. Using this function library, we download
the message headers and message body separately.
The three IMAP functions we use here are imap_header(), imap_fetchheader(), and
imap_body(). Note that the two header functions are distinct from imap_headers(), the one
we used previously. They are somewhat confusingly named. In summary,
• imap_headers()—Returns a summary of the headers for all the messages in a mailbox.
It returns them as an array with one element per message.
• imap_header()—Returns the headers for one specific message in the form of an object.
• imap_fetchheader()—Returns the headers for one specific message in the form of a
string.
In this case we use imap_header() to fill out specific header fields and imap_fetchheader()
to show the user the full headers if requested. (We’ll come back to this.)
We use
imap_header() and imap_body() to build an array containing all the elements of a
message that we are interested in.
We call
imap_header() as follows:
$header = imap_header($imap, $messageid);
We can then extract each of the fields we require from the object:
$message[‘subject’] = $header->subject;
We call imap_body() to add the message body to our array as follows:
$message[‘body’] = imap_body($imap, $messageid);
Building Practical PHP and MySQL Projects
P
ART V
646
LISTING 27.10 Continued
33 7842 CH27 3/6/01 3:41 PM Page 646