Peter Featherstone
Peter Featherstone

Reputation: 8102

How Do I Get The Specific Part For Each Email Using imap_fetchstructure()

I have a script where I am fetching an email body using imap_fetchbody( $inbox, $email_number, 1.1 );

However this is causing errors and I believe it is due to the last attribute (the part number) with me always giving it the value of 1.1 as sometimes the body of the message isn't actually held here.

Is there a way to determine which part number should be passed to this. Ideally it would be the correct part that contains the body text of the email, either in HTML or plain text I'm not fussed.

I have been searching around but none of the ones I have tried have worked.

Upvotes: 0

Views: 417

Answers (2)

Jan Kundrát
Jan Kundrát

Reputation: 3816

You have to parse and understand the part indexing; read RFC 3501 for details or search any of the zillion of stackoverflow questions about this topic.

Also, the 1.1 is supposed to be a string, not a floating point number. It's only due to a sheer luck that this happens to work for you on this particular value; do not rely on it.

Upvotes: 1

Peter Featherstone
Peter Featherstone

Reputation: 8102

I have found this which does an amazing job at solving this issue:

http://www.electrictoolbox.com/php-imap-message-body-attachments/

Upvotes: 1

Related Questions