★ wanayoo — archive 1999 http://www.php.net/manual/function.imap-header.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to IMAP
Quick Reference
German version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
IMAP
* imap_append
* imap_base64
* imap_body
* imap_check
* imap_close
* imap_createmailbox
* imap_delete
* imap_deletemailbox
* imap_expunge
* imap_fetchbody
* imap_fetchstructure
* imap_header
* imap_rfc822_parse_headers
* imap_headers
* imap_listmailbox
* imap_getmailboxes
* imap_listsubscribed
* imap_getsubscribed
* imap_mail_copy
* imap_mail_move
* imap_num_msg
* imap_num_recent
* imap_open
* imap_ping
* imap_renamemailbox
* imap_reopen
* imap_subscribe
* imap_undelete
* imap_unsubscribe
* imap_qprint
* imap_8bit
* imap_binary
* imap_scanmailbox
* imap_mailboxmsginfo
* imap_rfc822_write_address
* imap_rfc822_parse_adrlist
* imap_setflag_full
* imap_clearflag_full
* imap_sort
* imap_fetchheader
* imap_uid
* imap_msgno
* imap_search
* imap_last_error
* imap_errors
* imap_alerts
* imap_status
* imap_utf7_decode
* imap_utf7_encode
* imap_utf8
* imap_fetch_overview
* imap_mime_header_decode
* imap_mail_compose
* imap_mail
Manual: imap_header
View the source code for this pageSearch the site



Previous page
 imap_fetchstructure
 Updated
Sat, 12 Aug 2000
imap_rfc822_parse_headers 
Next page


imap_header

(PHP3 , PHP4 )

imap_header -- Read the header of the message

Description

object imap_header (int imap_stream, int msg_number [, int fromlength [, int subjectlength [, string defaulthost]]])

This function returns an object of various header elements.


       remail, date, Date, subject, Subject, in_reply_to, message_id,
       newsgroups, followup_to, references

message flags:
   Recent -  'R' if recent and seen, 
             'N' if recent and not seen, 
             ' ' if not recent
   Unseen -  'U' if not seen AND not recent, 
             ' ' if seen OR not seen and recent
   Answered -'A' if answered, 
             ' ' if unanswered
   Deleted - 'D' if deleted, 
             ' ' if not deleted
   Draft -   'X' if draft, 
             ' ' if not draft
   Flagged - 'F' if flagged, 
             ' ' if not flagged

NOTE that the Recent/Unseen behavior is a little odd. If you want to
know if a message is Unseen, you must check for

Unseen == 'U' || Recent == 'N'

toaddress (full to: line, up to 1024 characters)

to[] (returns an array of objects from the To line, containing):
   personal
   adl
   mailbox
   host

fromaddress (full from: line, up to 1024 characters)

from[] (returns an array of objects from the From line, containing):
   personal
   adl
   mailbox
   host

ccaddress (full cc: line, up to 1024 characters)
cc[] (returns an array of objects from the Cc line, containing):
   personal
   adl
   mailbox
   host

bccaddress (full bcc line, up to 1024 characters)
bcc[] (returns an array of objects from the Bcc line, containing):
   personal
   adl
   mailbox
   host

reply_toaddress (full reply_to: line, up to 1024 characters)
reply_to[] (returns an array of objects from the Reply_to line,
containing):
   personal
   adl
   mailbox
   host

senderaddress (full sender: line, up to 1024 characters)
sender[] (returns an array of objects from the sender line, containing):
   personal
   adl
   mailbox
   host

return_path (full return-path: line, up to 1024 characters)
return_path[] (returns an array of objects from the return_path line,
containing):
   personal
   adl
   mailbox
   host

udate (mail message date in unix time)

fetchfrom (from line formatted to fit fromlength 
characters)

fetchsubject (subject line formatted to fit subjectlength characters)
      


User Contributed Notes: imap_header


teo@digiro.net
25-Mar-1999 11:45
This function is also imap_headerinfo()'s alias
, which is not documented(as many others) and
also returns as members From,From2,To,ReplyTo,
Recent,Unseen,Flagged,Answered,Deleted.Msgno,MailDate,Size - for details seek for imap.c and imap.h in the distribution.



gudmundsdottir@bigfoot.com
07-Jul-1999 11:51
The Unseen member returns "U" or FALSE, not TRUE or FALSE. This probably applies to other flag members, but I haven't tested them.


neilwi@demon.net
08-Jul-1999 12:29
As above, the Recent flag returns "N" or FALSE. (Presumably "N" is for "New).


boy_hong@hotmail.com
05-Jan-2000 11:03
I find that the "subject" of header maybe encoded like "=?big5?B?rNW0SbDyqvemXqb+?= " or "=?ISO-8859-1?Q?=A4=A4=A4=E5=BC=D0=C3D?= ". I guest that they are character set big5 and is0-8895-1. And the 'Q' in the second one is quoted-printable. Do anyone know that how to decode these string? I've tried to use imap_qprint and quoted_printable_decode to decode the one with 'Q', it works. But I don't know the meaning of 'B' and I find that it should not be base64. Besides, as I use quoted_printable_decode() to decode the '=?ISO-8859-1?Q?=A4=A4=A4=E5=BC=D0=C3D?= ' string, I can only convert '=A4=A4=A4=E5=BC=D0=C3D'. I can't remove '=?ISO-8859-1?Q?' and the ending '?='. It seems that it's not straight forward like the decoding of body message.


bernard@bmpsystems.com
13-Feb-2000 08:30
I found the problem to my question above. I need to use htmlspecialchars on the resultstring of the address, else the "<" and ">" would make the e-mail adr. invisible because the browser thinks it is a HTML tag. Silly me.


aragorn@afrodita.phys,msu.su
25-Mar-2000 07:34
Message size can be obtained by using this statement:
<PRE>
$str = imap_fetchstructure($mbox,$msgn);
</PRE>
size in bytes is <B>$str->bytes</B>.



hpkevertje@hotmail.com
27-Mar-2000 06:31
To use the from[] and to[] functions, try this:
<PRE>$from=header->from;</PRE>
<PRE>$fromadr=$from->presonal;</PRE>



ed@lexingrad.net
17-Apr-2000 04:06
Use something like this to display the number
of new messages:

<pre>
/*$new_messages = 0;
for( $i=0 ; $i < $nummsg ; $i++ ) {
$msg = imap_header($mailbox, $msg_array[$i]);
if ($msg->Unseen == "U"|| $msg->Recent == "N") {
$new_messages = $new_messages + 1;
}
}
echo "
$new_messages NEW Messages";*/
</pre>
uncommented of course : ~)



crazyj@internetion.co.kr
20-Apr-2000 11:55
I solved the problem that $header->to or $header->from.

----try this code....

$header = imap_header($mbox, $num);
$from = $header->from[0];
$to = $header->to[0];
while (list($key, $val) = each($from))
echo "$key => $val
";
while (list($key, $val) = each($to))
echo "$key => $val
";
--------------
i tried $from=$header->from[0] insted of $from=$header->from.




G.li@open.ac.uk
05-Jul-2000 03:26
Yes, the ref. is quit confusing (to me at least). It will be wise (after spent many hours) to test the type of variable first before it disappointe you. I find $header->From retrurns String, $header->from returns array and its elements are object. Therefore if you want get sender's name for example,
you need: $from = $header->from;

if (is_array($from)){

while(list($key, $val) = each($from)) {

echo $from[0]->personal;
echo $from[0]->adl;
echo $from[0]->mailbox;
echo $from[0]->host;

}
}
you will find $header_from is an one element array and this element is an object. Hope anyone else will not wast time here to figure out why retrun is empty.



mayorga@tadecom.com
02-Aug-2000 11:44
If you want to retrieve From address, not From name, use this:
$from=$header->from; $fromaddr=sprintf("%s@%s",$from[0]->mailbox,$from[0]->host);



lint@phpcult.com
02-Aug-2000 06:51
here's something even easier:


<pre>
$header = imap_header($mail_connection, msgnum);
$from = htmlspecialchars($header->fromaddress);
echo $from;
</pre>



jheathco@home.com
10-Aug-2000 02:59
Well I got the headers to work... try something like this...

$msg_header = imap_header($mailbox, 1);

print $msg_header->from[0]->mailbox . "@" . $msg_header->from[0]->host;



 About Notes


Previous page
 imap_fetchstructure
 Updated
Sat, 12 Aug 2000
imap_rfc822_parse_headers 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.