Entry
How do I get the header information from a message using IMAP?
How to save to a file, the message source, with all the hearder information, body and mime parts, to
Jun 9th, 1999 07:00
Nathan Wallace, Dany Blue, Murat Arslan
...
// connect to imap host
$imapstr = imap_open("{$imap_host:$imap_port}$imap_mbox", $user, $pass);
if($imapstr == 0) {
echo "Error!\n";
exit();
}
...
...
// get header of mail $mailnum
$message_header = imap_header($imapstr, $mailnum);
// get message num of $mailnum,
// if you sort your mbox, $mailnum can not be equal to $msgno.
$msgno = $message_header->Msgno;
// date of the message
$date = date("m/d - H:i", $message_header->udate);
// size,
$size = $message_header->Size;
// subject,
$subject = $message_header->subject;
// from part
$from_obj = $message_header->from[0];
// assigning $from var.
if($from_obj->personal == "") {
$from = htmlspecialchars(substr($from_obj->mailbox . "@" .
strtolower($from_obj->host), 0, 30));
} else {
$from = htmlspecialchars($from_obj->personal);
}
// assigning $to and $cc vars, if needed.
$to_array = $message_header->to;
$cc_array = $message_header->cc;
...