(PHP 3, PHP 4, PHP 5)

imap_body -- Read the message body


string imap_body ( resource imap_stream, int msg_number [, int options] )

imap_body() returns the body of the message, numbered msg_number in the current mailbox.

The optional options are a bit mask with one or more of the following:

  • FT_UID - The msg_number is a UID

  • FT_PEEK - Do not set the \Seen flag if not already set

  • FT_INTERNAL - The return string is in internal format, will not canonicalize to CRLF.

imap_body() will only return a verbatim copy of the message body. To extract single parts of a multipart MIME-encoded message you have to use imap_fetchstructure() to analyze its structure and imap_fetchbody() to extract a copy of a single body component.

add a note add a note User Contributed Notes
webmaster at pedro dot frandt dot com
07-Mar-2005 01:36
I was having a problem where I was connecting to a POP3 server and no matter what I did PHP always said there was as many unread messages as there was messages in total.

After about an hour of Googling I found this in a comment in an existing file:

> POP3 considers ALL messages as "unseen" and/or "recent" because POP3 does not retain such info as seen or unseen

I hope this helps you save some time.
11-Sep-2003 09:09
Usually, not multipart or 'zero-parts' messages are displayed with imap_body, but you may have a multipart message with no parts. For this type, displaying with imap_body, you may get unwanted data(like 'this is a MIME...' and boundary string), so a better solution is use imap_fetchbody.

// Type 1 is 'multipart'
if(($struct->type==1) && (sizeOf($struct->parts)==0))

Where $struct is the object returned by imap_fetchstructure.
jh at junetz dot de
02-Jul-2003 07:37
If you read the description of options carefully you'll see that imap_body() marks messages as read (SEEN) by default. Note that if you parse messages containing MIME using some of the other imap functions and don't call imap_body() in such a case, the messages will probably still be unread.

For example in a webmail environment you may have collected enough information to display a particular message simply by parsing the MIME content with no need to call imap_body(). In this case you can use imap_setflag_full(stream, sequence, "\\SEEN", options) to explicitly mark it as read.