Your code $message = imap_fetchbody($openmail, $i, 2, FT_PEEK);
uses hardcoded part offsets, i.e. it assumes that a message is always multipart/alternative
with text/plain
and text/html
. That's a very wrong assumption.
You have to look at the output of the BODYSTRUCTURE
to see what the MIME structure of your mail is.
With that out of the way, be sure that none of your commands use the BODY
fetch operation; you have to use BODY.PEEK
. I have no idea how this is accessible within the PHP c-client bindings.