Take the 2-minute tour ×

I am creating an email client and going through many problems. Now the latest problem which I am facing is to show embedded images on the HTML email body.

My email body code looks similar to this:

<img alt="image001" src="cid:image001.gif@01CCB988.809DD560" id="Picture_x0020_1" />

Few related posts are found, but they are not useful. Also looking for other possible similar problems while displaying mail contents.

I am using PHP IMAP with POP3 to fetch mails. Currently using gmail as mail server. Sending mails using SMTP (PhpMailer).

Thanks in advance.

share|improve this question
add comment

2 Answers

Did you use:

$mail->AddEmbeddedImage(filename, cid, name);
//By using this function with this example's value above, results in this code:
$mail->AddEmbeddedImage('my-photo.jpg', 'my-photo', 'my-photo.jpg ');

If yes, what is going wrong? Why are you not happy.

Please note that by default, most email clients do not show embedded images, this is goes for Gmail and Outlook. You can not circumvent that. Its a security / bandwith saving feature. The user would first have to press 'Show images' before they appear.

share|improve this answer
I am not sending mail. I am showing mails from my inbox. On my inbox, there are several types of formatted mails. One format is the embedded image which I mentioned. I want to show the image on my online mail client. Just need to display the mail body as same as viewing in gmail or other mail clients. –  IvenMS Dec 22 '11 at 7:17
Do you have access to the image attachment with the name image001.gif –  saratis Dec 22 '11 at 7:24
I can get the image from attachments. –  IvenMS Apr 12 '12 at 12:33
add comment

In HTML, images are standalones documents with a specific URI (used by src="" attribute). In your MIME boby, this src attribute refer to a relative MIME part. So, you'll need to write all MIME parts contents in a distinct file (i.e. /tmp/[md5_MIME_PART_ID]) Then use a CGI script to rewrite the email body and forward specific mime request :


if($_GET['mime']) {
$contents = preg_replace("/sid:/", "readmail.php?mime=$1", $contents);
echo $contents;

Of course, a proper database system will be more efficient here, but that's a start

share|improve this answer
Thanks for the reply. I am not clear about the answer you explained. In the mail body, the image data is given in parts of the mail and each part is identifying with CID. HTML body using this CID in the img src to show data. Mail clients can read this and can show this. But how can an POP3 based imap mail client show this image data as images inside the HTML content. Please suggest me with your ideas. –  IvenMS Dec 22 '11 at 11:35
add comment

Your Answer


