Hello,

I am retrieving html out of a multipart message using: $html = imap_fetchbody($imapStream, $emailId, '2'); And I am retrieving plain text by using $plain = imap_fetchbody($imapStream, $emailId, '1'); My question is: Why is this working? I got this to work through trial and error. I don't know why I am using 1 or 2 as the third parameter. I looked up various examples online and they all use different values such as 2.1, 1.2, etc.

for example take a look at Adam's post on http://theserverpages.com/php/manual/en/function.imap-fetchbody.php
He lists the parts as following:

0 multipart/mixed
   1 multipart/alternative
       1.1 text/plain
       1.2 text/html
   2 message/rfc822
       2 multipart/mixed
           2.1 multipart/alternative
               2.1.1 text/plain
               2.1.2 text/html
           2.2 message/rfc822
               2.2 multipart/alternative
                   2.2.1 text/plain
                   2.2.2 text/html

Also please take look at http://www.bitsense.net/PHPNotes/IMAP/imap_fetchstructure.asp/
On that page the parts are listed as

()Root Message Part (multipart/related)
(1) The text parts of the message (multipart/alternative)
(1.1) Plain text version (text/plain)
(1.2) HTML version (text/html)
(2) The background stationary (image/gif)

If either one of these lists were correct, my script should fail. But so far it hasn't. So why is my script working?

I would like learn how to use this function properly so my script won't stop working one day.
I thank you in advance for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.