Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to attach image email on laravel 5.3 using Mail Facade?

Tags:

laravel

I got image on mail template but when i send it does not carry the image. what should i do.

Template HTML

<img src="/img/blahblah.jpg"> //this image does not display on receiver of mail

App\Mail\Subscribe

public function build() {
  return $this->view('mail.subscribe');
}
like image 233
Jhon Rey Avatar asked Dec 15 '16 13:12

Jhon Rey


2 Answers

To embed an inline image, use the embed method on the $message variable within your email template. Laravel automatically makes the $message variable available to all of your email templates, so you don't need to worry about passing it in manually

<img src="{{ $message->embed($pathToFile) }}">

https://laravel.com/docs/5.3/mail#inline-attachments

like image 84
Alexey Mezenin Avatar answered Nov 15 '22 08:11

Alexey Mezenin


In your mail template use the asset helper function to get the full url of the image as:

<img src="{{ asset('img/blahblah.jpg') }}">

From docs

Generate a URL for an asset using the current scheme of the request (HTTP or HTTPS)

Check out the docs.

like image 34
Amit Gupta Avatar answered Nov 15 '22 07:11

Amit Gupta