downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

imap_last_error> <imap_headerinfo
Last updated: Fri, 05 Feb 2010

view this page in

imap_headers

(PHP 4, PHP 5)

imap_headersReturns headers for all messages in a mailbox

Description

array imap_headers ( resource $imap_stream )

Returns headers for all messages in a mailbox.

Parameters

imap_stream

An IMAP stream returned by imap_open().

Return Values

Returns an array of string formatted with header info. One element per mail message.



add a note add a note User Contributed Notes
imap_headers
jose dot yapur at usmp dot pe
25-Dec-2009 09:28
Some example of how to use it:

<?php
    $imap
= imap_open("{mail.example.com:143}INBOX", "username", "password");
   
$message_count = imap_num_msg($imap);

    for (
$i = 1; $i <= $message_count; ++$i) {
       
$header = imap_header($imap, $i);
       
$body = trim(substr(imap_body($imap, $i), 0, 100));
       
$prettydate = date("jS F Y", $header->udate);

        if (isset(
$header->from[0]->personal)) {
           
$personal = $header->from[0]->personal;
        } else {
           
$personal = $header->from[0]->mailbox;
        }

       
$email = "$personal <{$header->from[0]->mailbox}@{$header->from[0]->host}>";
        echo
"On $prettydate, $email said \"$body\".\n";
    }

   
imap_close($imap);
?>
mmuoio at gmail dot com
12-Oct-2009 05:39
This function will not return a full subject line if it is longer than 25 characters.  I found this out after trying to search each header and move the email to a different folder depending on what the subject was (searching for year and project number).

imap_last_error> <imap_headerinfo
Last updated: Fri, 05 Feb 2010
 
 
show source | credits | sitemap | contact | advertising | mirror sites