Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Show Image attachment in Email body?


Go to End


4 Posts   1969 Views

Avatar
Pix

Community Member, 158 Posts

9 April 2013 at 7:40am

Hi,

I have a form which sends an e-mail with an image attachment. I was wondering how would I also display the image in the body of the e-mail? I was reading how the src must reference 'cid' or something like that, so I tried:

<img src="cid: name-of-attachment.jpg" alt="pic">

But did't work, maybe there is a better way with SilverStripe? The image must be sent as an attachment, it will not live on the server, so I need to reference the src from the email somehow.

Thank you!

Avatar
Pix

Community Member, 158 Posts

11 April 2013 at 7:01am

Edited: 11/04/2013 7:04am

Just kind of wondering about this.....that's all.....

So, this is good

$email->attachFile("myImage.jpg");

but (this doesn't work):

<img src="myImage.jpg" alt="my image">

in the email template. How to reference the attached image? Anyone?

Avatar
przemo

Community Member, 1 Post

22 October 2015 at 8:11pm

Hello,

I have the same problem, i don't know how to make image visible in html email body.

<img src="myImage.jpg" /> don't works

<img src="cid:myImage.jpg" /> don't works

it must be somehow possible, please help me :)

Avatar
Devlin

Community Member, 344 Posts

22 October 2015 at 9:09pm

There is currently no support for Content-ID in SilverStripe.

But you could embed the image as a base64 string. Something like:

$base64 = base64_encode(file_get_contents(Director::getAbsFile('mysite/images/logo.png')));

$mail = new Email();
$mail->setBody('<img src="data:image/png;base64,' .  $base64 . '">');