I am working on mailbox using imap php. I am using imap_fetchbody($mbox, 4,2) to read the contents of mail. It works fine for normal text messages but when the email has inline images (not attachment) or html template its not working properly. It simply returns some encrypted code. I referred many codes. The one i used is:
$mbox = imap_open($hostname,$username,$password)
or die('Cannot connect to Gmail: ' . imap_last_error());
$message=imap_fetchbody($mbox, 4,2);
$decoded_data = base64_decode($message);
file_put_contents('image002.jpg',$decoded_data);
<img src="image002.jpg">
It fetches the inline image but if the mail has more than one inline image it returns only the last image.I don't have any idea on how to get the html template message can anyone help me?