Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: How to embed image in an email as a content and not as an attachment

I have searched for ways to embed an image in an email sent with Laravel. The method I have found which most people use is to embed the image as an attachment.

<img src="{{$message->embed(asset('assets/img/logo.png'))}}" style="padding:0px; margin:0px" />

Is there a way to embed an image without it being an attachment? I tried converting the image to base64 strings but that didn't even work.

like image 749
BlackPearl Avatar asked Nov 01 '14 20:11

BlackPearl


People also ask

How do you embed an image into an email?

Email providers, like Gmail, allow you to drag an image from a folder and drop it into an area inside the compose box that says “attach files here”. Gmail will automatically embed the image and realign it so it's in line with the rest of the plain text.

What does it mean to embed an image in an email?

Embedding an image into an email message is the act of adding the image into the coding of the email template for it to appear amongst the text once the subscriber opens it, instead of appearing as an email attachment.

What does it mean to embed in an email?

In a nutshell, embedding an image means adding it into the text of the email message. Hence, making it appear exactly as it is on a website rather than as an attachment.


1 Answers

Whether its a good thing or not...

You nearly have it. I suppose the problem is that the asset() function is generating a full url and Laravel need the path to the file. Official Doc

Try this:

<img src="{{ $message->embed('assets/img/logo.png') }}" style="padding:0px; margin:0px" />
like image 50
lukasgeiter Avatar answered Oct 03 '22 00:10

lukasgeiter