I am using mailgun. now i am sending mail from gmail to my domain. using mailgun api i am getting that and showing that content in my webpage. but when i am adding images in middle of the text or in signature of the mail image is not showing in webpage. it is just showing broken image because it is showing like this:

<img width="375" height="134" src="cid:ii_i2davb0f0_1499f1c3646e87a5">

How can i show these images in web page?

using jsondecode i am decoding this content-id-map ==> {\"<ii_i2ecp4vs0_149a2e5b77d06876>\": \"attachment-1\"}

but how to copy this file into my sustem and how to replace it with my src attr. is there any library for this?

i did like this...but not working

$str="{\"ii_i2ecp4vs0_149a2e5b77d06876\": \"attachment-1\"}";

$json = preg_replace_callback('/"":/', function($m) {
    return '"' . uniqid() . '":';
}, $str);

foreach($jsonarry as $key=>$val)
    $im= base64_decode+($key);
    echo "<img src='test.png'>";

Member Avatar

This is the documentation I found:

Sending Inline Images
Mailgun assigns content-id to each image passed via inline API parameter, so it can be referenced in HTML part.

Example of sending inline image. Note how image is referenced in HTML part simply by the filename:

curl -s --user 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0' \
    https://api.mailgun.net/v2/samples.mailgun.org/messages \
    -F from='Excited User <me@samples.mailgun.org>' \
    -F to='alice@example.com' \
    -F subject='Hello' \
    -F text='Testing some Mailgun awesomness!' \
    --form-string html='<html>Inline image here: <img src="cid:cartman.jpg"></html>' \
    -F inline=@files/cartman.jpg

From http://documentation.mailgun.com/user_manual.html#sending-via-api

So this means if you copy the body text you'll get the reference only. It doesn't actually mean anything outside the scope of the email message itself.

I think I created an imap attachment download class a little while ago, that may be useful if you want to automate posting data with attachments from email to your webpage.

An alternative would be to host inline images on a publically accessible site and just provide the full external url in the link. I think.

An alternative would be to host inline images on a publically accessible site and just provide the full external url in the link. I think.

yes my requirement is your alternate method. could you please help me how to achieve it

Member Avatar

Not sure, never tried it. But I'm assuming that you could host an image on a site like:


So then you just link to it in your body text:

<img width="375" height="134" src="http://www.example.com/images/user/diafol/embarrassing.png">

That way you don't need to send the image as an attachment. However, the image is not available to the recipient when they are offline. Something to weigh up.

i am talking about receiving emails not about sending emails via my site.

i am getting mails from gmail,yahoo,etc., so i want to show email inline images in my webpage.

here is the line how i am getting attachment.
$str="{\"ii_i2ecp4vs0_149a2e5b77d06876\": \"attachment-1\"}";

so how to parse this and upload this into my image folder

Member Avatar

OK so why mailgun? I got the impression that you were trying to send images. When I started discussing sending images you said "yes" this is what you were trying to do.

I created an imap download attachment class a little while ago here: https://www.daniweb.com/web-development/php/code/486230/email-attachment-downloader-and-extract-archive-content-class

It's a little rough and ready but does the trick AFAIK. You have the attachment reference (attachment1) - so get the first attachment name (or create one) and change the src in the html of the email.

Be a part of the DaniWeb community

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