Embedding image in laravel markdown email

Viewed 5955

I'm trying to embed an image into my markdown email but it's not loading correctly.

https://i.imgur.com/lNCwhod.png

This is my mail template:

@component('mail::message')
# {{ $mailData['title'] }}

![{{ $mailData['appName'] }}]({{ asset($mailData['image'])}})

{!! $mailData['body'] !!}

Saludos,

{{ $mailData['appName'] }}
@endcomponent

This is the value of $mailData['image']:

'/img/misc/default.jpg'

Any idea how I can do this?

2 Answers

You can use html to add an image to your markdown:

@component('mail::message')
# {{ $mailData['title'] }}

<img src="{{asset('img/logo.png')}}" style="width:30%" alt="App Logo">

...

@endcomponent

Also you can use the style tag to customize the image.

Be aware if you are in localhost, you aren't going to see the image in the email (unless you are using mailhogh to test your emails).

As far as I know, the image has to be in your server hosted, so the image will not attached on the email.

Your server need an IP public or a domain to be able to see the images within the email.

You can try this markdown:

![Image_Alter_Text](PAHT_OF_IMAGE)
  • You have to pass complete path of image, and you get complete path by using Storage::url($file_name). Store image path in variable and pass in markdown.

For example :

![DemoImage](https://i.stack.imgur.com/bENi3.jpg)

Note: The image (logo of stackoverflow) is used in this comments is only for demo purpose.

Related