Not receiving the $message variable in view from a Laravel HTML Mailable (NON Markdown)












6

















I've read several similar questions related to this problem but all refer to Markdown mailables.



I'm trying to send inline images in the mailables but I haven't found a way to do it properly (Laravel 5.5).



The documentation says this:




Inline Attachments



Embedding inline images into your emails is typically cumbersome; however, Laravel provides a convenient way to attach images to your emails and retrieving the appropriate CID. 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:



<body>
Here is an image:

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



But, when doing that I receive this error:




Undefined variable: message (View: /path/to/project/resources/views/mails/new_user_welcome.blade.php)




I know that this has a limitation when using a Markdown message but I'm not using one.





This are the related files:



Mail/NewUserWelcomeEmail.php



class NewUserWelcomeEmail extends Mailable
{
use SerializesModels;

public function build()
{
return $this->view('mails.new_user_welcome');
}
}


Resources/views/mails/new_user_welcome.blade.php



@extends('layouts.mail')

@section('content')

<img src="{{ $message->embed(url("storage/images/inline_image.png")) }}"
alt="An inline image" />

@endsection


App/Http/Controllers/UserController.php



public function register(NewUserRequest $request)
{
// some code

Mail::to($user)->send(new NewUserWelcomeEmail($user));

return 'done';
}









share|improve this question

























  • try to pass messages with contstruct.

    – Ali Özen
    May 9 '18 at 8:11











  • Hello @AliÖzen, how do I do that?

    – HCK
    May 9 '18 at 8:13











  • Perhaps it fails somewhere else, because it should work like this..

    – ndberg
    May 15 '18 at 6:12
















6

















I've read several similar questions related to this problem but all refer to Markdown mailables.



I'm trying to send inline images in the mailables but I haven't found a way to do it properly (Laravel 5.5).



The documentation says this:




Inline Attachments



Embedding inline images into your emails is typically cumbersome; however, Laravel provides a convenient way to attach images to your emails and retrieving the appropriate CID. 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:



<body>
Here is an image:

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



But, when doing that I receive this error:




Undefined variable: message (View: /path/to/project/resources/views/mails/new_user_welcome.blade.php)




I know that this has a limitation when using a Markdown message but I'm not using one.





This are the related files:



Mail/NewUserWelcomeEmail.php



class NewUserWelcomeEmail extends Mailable
{
use SerializesModels;

public function build()
{
return $this->view('mails.new_user_welcome');
}
}


Resources/views/mails/new_user_welcome.blade.php



@extends('layouts.mail')

@section('content')

<img src="{{ $message->embed(url("storage/images/inline_image.png")) }}"
alt="An inline image" />

@endsection


App/Http/Controllers/UserController.php



public function register(NewUserRequest $request)
{
// some code

Mail::to($user)->send(new NewUserWelcomeEmail($user));

return 'done';
}









share|improve this question

























  • try to pass messages with contstruct.

    – Ali Özen
    May 9 '18 at 8:11











  • Hello @AliÖzen, how do I do that?

    – HCK
    May 9 '18 at 8:13











  • Perhaps it fails somewhere else, because it should work like this..

    – ndberg
    May 15 '18 at 6:12














6












6








6


1








I've read several similar questions related to this problem but all refer to Markdown mailables.



I'm trying to send inline images in the mailables but I haven't found a way to do it properly (Laravel 5.5).



The documentation says this:




Inline Attachments



Embedding inline images into your emails is typically cumbersome; however, Laravel provides a convenient way to attach images to your emails and retrieving the appropriate CID. 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:



<body>
Here is an image:

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



But, when doing that I receive this error:




Undefined variable: message (View: /path/to/project/resources/views/mails/new_user_welcome.blade.php)




I know that this has a limitation when using a Markdown message but I'm not using one.





This are the related files:



Mail/NewUserWelcomeEmail.php



class NewUserWelcomeEmail extends Mailable
{
use SerializesModels;

public function build()
{
return $this->view('mails.new_user_welcome');
}
}


Resources/views/mails/new_user_welcome.blade.php



@extends('layouts.mail')

@section('content')

<img src="{{ $message->embed(url("storage/images/inline_image.png")) }}"
alt="An inline image" />

@endsection


App/Http/Controllers/UserController.php



public function register(NewUserRequest $request)
{
// some code

Mail::to($user)->send(new NewUserWelcomeEmail($user));

return 'done';
}









share|improve this question


















I've read several similar questions related to this problem but all refer to Markdown mailables.



I'm trying to send inline images in the mailables but I haven't found a way to do it properly (Laravel 5.5).



The documentation says this:




Inline Attachments



Embedding inline images into your emails is typically cumbersome; however, Laravel provides a convenient way to attach images to your emails and retrieving the appropriate CID. 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:



<body>
Here is an image:

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



But, when doing that I receive this error:




Undefined variable: message (View: /path/to/project/resources/views/mails/new_user_welcome.blade.php)




I know that this has a limitation when using a Markdown message but I'm not using one.





This are the related files:



Mail/NewUserWelcomeEmail.php



class NewUserWelcomeEmail extends Mailable
{
use SerializesModels;

public function build()
{
return $this->view('mails.new_user_welcome');
}
}


Resources/views/mails/new_user_welcome.blade.php



@extends('layouts.mail')

@section('content')

<img src="{{ $message->embed(url("storage/images/inline_image.png")) }}"
alt="An inline image" />

@endsection


App/Http/Controllers/UserController.php



public function register(NewUserRequest $request)
{
// some code

Mail::to($user)->send(new NewUserWelcomeEmail($user));

return 'done';
}






laravel email laravel-5.5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 19:39







HCK

















asked May 9 '18 at 8:09









HCKHCK

3,60711238




3,60711238













  • try to pass messages with contstruct.

    – Ali Özen
    May 9 '18 at 8:11











  • Hello @AliÖzen, how do I do that?

    – HCK
    May 9 '18 at 8:13











  • Perhaps it fails somewhere else, because it should work like this..

    – ndberg
    May 15 '18 at 6:12



















  • try to pass messages with contstruct.

    – Ali Özen
    May 9 '18 at 8:11











  • Hello @AliÖzen, how do I do that?

    – HCK
    May 9 '18 at 8:13











  • Perhaps it fails somewhere else, because it should work like this..

    – ndberg
    May 15 '18 at 6:12

















try to pass messages with contstruct.

– Ali Özen
May 9 '18 at 8:11





try to pass messages with contstruct.

– Ali Özen
May 9 '18 at 8:11













Hello @AliÖzen, how do I do that?

– HCK
May 9 '18 at 8:13





Hello @AliÖzen, how do I do that?

– HCK
May 9 '18 at 8:13













Perhaps it fails somewhere else, because it should work like this..

– ndberg
May 15 '18 at 6:12





Perhaps it fails somewhere else, because it should work like this..

– ndberg
May 15 '18 at 6:12












4 Answers
4






active

oldest

votes


















4
















Well, to be honest, I have not found a way to make this work properly. I mean, as it stands, this should work. Maybe is my Laravel installation (?)..



Anyway, I did make it work with a workaround.



1) Using Eduardokum' Laravel Mail Auto Embed package, this basically generate a CID for each of your media assets.



But after adding this package this didn't work as expected.. so I:



2) change the way I was referencing my assets, from this:



   <img src="{{ url("storage/a_inline_image.png") }}" />


To this:



   <img src="{{ asset("storage/a_inline_image.png") }}" />


Now it works.






share|improve this answer
























  • for my personal reference, it would be great, to know, if it worked using asset(... without any additional packages?

    – Bart
    May 18 '18 at 23:19






  • 2





    @bart no, it didn't work. The original problem wasn't the way I referenced assets but the $message variable. Sadly, I haven't found a way to make it worked. And yes, I try what (I assume) you are suggesting but as I said, it didn't work :/

    – HCK
    May 18 '18 at 23:56











  • thanks for update :)

    – Bart
    May 19 '18 at 17:47



















1
















if you can use like this than it can be work other wise you don't use $message variable in mail blade



Mail::send('emails.welcome', $data, function ($message) {
$message->from('us@example.com', 'Laravel');
$message->to('foo@example.com')->cc('bar@example.com');
});


if you don't want use this method than you can use like this



https://code.tutsplus.com/tutorials/how-to-send-emails-in-laravel--cms-30046



it can be work like this.






share|improve this answer


























  • The documentations says this: "Laravel automatically makes the $message variable available to all of your email templates" so it should be available.

    – HCK
    May 13 '18 at 22:52



















1
















In my case (Larvel 5.5), I've managed, to modify header logo, in both html and markdown.



Laravel documentation, although really great, could be better in this regard.



Anyway, follow these steps, and you should be fine...



1 - Publish mail templates via:



php artisan vendor:publish --tag=laravel-mail


so you can easily modify your mail source files.



2 - Modify message.blade.php in resources/views/vendor/mail/html with this:



@slot('header')
@component('mail::header', ['url' => config('app.url')])
<img src="{{asset('assets/img/pathToYourImage...')}}">
@endcomponent
@endslot


3 - All your emails should receive logo via CID from now.



Note:



In this example Laravel, automatically converts assets to CIDs, so you don't need to call $message->embed(... at all...



Please test extensively, with these html/markdown directories and blade directives going on. It is kinda tricky, but it definitely, does its magic...






share|improve this answer


























  • My laravel 5.5 is not changing the URL for a CID id, it's just sending the url.

    – Don Viegues
    Aug 10 '18 at 19:12











  • @DonViegues are you sure you are using asset() function? If that's the case.maybe you should try package suggested by HCK in this thread - Laravel Mail Auto Embed.. BTW I believe this is a bug, and I hope it was fixed in Laravel 5.6. Can you verify that?

    – Bart
    Aug 11 '18 at 0:43











  • Hi, yes, I'm using asset(), it seems that the package you said is the way to go. thanks.

    – Don Viegues
    Aug 16 '18 at 20:35



















1














You have to define the File Path Variable in your Mailable as public property -> example $pathToFile.



If you have the file path from outside of the mailable you can pass in with the constructor.



class NewUserWelcomeEmail extends Mailable
{
use SerializesModels;

// Must be public
public $pathToFile;

/**
* Create a new message instance.
*/
public function __construct(string $pathToFile)
{
$this->pathToFile= $pathToFile;
}

public function build()
{
return $this->view('mails.new_user_welcome');
}
}


Then it works as expected in your view like this:



@extends('layouts.mail')

@section('content')

<img src="{{ $message->embed(url($pathToFile)) }}" alt="An inline image" />

@endsection





share|improve this answer


























  • The problem is the $message variable not the ones flagged as public in the Mailable class.

    – HCK
    May 15 '18 at 6:06













  • oh I see, could have read better.

    – ndberg
    May 15 '18 at 6:10











  • Don't worry, I solved the issue with a workaround.. I'll update it tomorrow. Thanks anyway, mate.

    – HCK
    May 15 '18 at 6:11











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50248498%2fnot-receiving-the-message-variable-in-view-from-a-laravel-html-mailable-non-ma%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























4 Answers
4






active

oldest

votes








4 Answers
4






active

oldest

votes









active

oldest

votes






active

oldest

votes









4
















Well, to be honest, I have not found a way to make this work properly. I mean, as it stands, this should work. Maybe is my Laravel installation (?)..



Anyway, I did make it work with a workaround.



1) Using Eduardokum' Laravel Mail Auto Embed package, this basically generate a CID for each of your media assets.



But after adding this package this didn't work as expected.. so I:



2) change the way I was referencing my assets, from this:



   <img src="{{ url("storage/a_inline_image.png") }}" />


To this:



   <img src="{{ asset("storage/a_inline_image.png") }}" />


Now it works.






share|improve this answer
























  • for my personal reference, it would be great, to know, if it worked using asset(... without any additional packages?

    – Bart
    May 18 '18 at 23:19






  • 2





    @bart no, it didn't work. The original problem wasn't the way I referenced assets but the $message variable. Sadly, I haven't found a way to make it worked. And yes, I try what (I assume) you are suggesting but as I said, it didn't work :/

    – HCK
    May 18 '18 at 23:56











  • thanks for update :)

    – Bart
    May 19 '18 at 17:47
















4
















Well, to be honest, I have not found a way to make this work properly. I mean, as it stands, this should work. Maybe is my Laravel installation (?)..



Anyway, I did make it work with a workaround.



1) Using Eduardokum' Laravel Mail Auto Embed package, this basically generate a CID for each of your media assets.



But after adding this package this didn't work as expected.. so I:



2) change the way I was referencing my assets, from this:



   <img src="{{ url("storage/a_inline_image.png") }}" />


To this:



   <img src="{{ asset("storage/a_inline_image.png") }}" />


Now it works.






share|improve this answer
























  • for my personal reference, it would be great, to know, if it worked using asset(... without any additional packages?

    – Bart
    May 18 '18 at 23:19






  • 2





    @bart no, it didn't work. The original problem wasn't the way I referenced assets but the $message variable. Sadly, I haven't found a way to make it worked. And yes, I try what (I assume) you are suggesting but as I said, it didn't work :/

    – HCK
    May 18 '18 at 23:56











  • thanks for update :)

    – Bart
    May 19 '18 at 17:47














4












4








4









Well, to be honest, I have not found a way to make this work properly. I mean, as it stands, this should work. Maybe is my Laravel installation (?)..



Anyway, I did make it work with a workaround.



1) Using Eduardokum' Laravel Mail Auto Embed package, this basically generate a CID for each of your media assets.



But after adding this package this didn't work as expected.. so I:



2) change the way I was referencing my assets, from this:



   <img src="{{ url("storage/a_inline_image.png") }}" />


To this:



   <img src="{{ asset("storage/a_inline_image.png") }}" />


Now it works.






share|improve this answer















Well, to be honest, I have not found a way to make this work properly. I mean, as it stands, this should work. Maybe is my Laravel installation (?)..



Anyway, I did make it work with a workaround.



1) Using Eduardokum' Laravel Mail Auto Embed package, this basically generate a CID for each of your media assets.



But after adding this package this didn't work as expected.. so I:



2) change the way I was referencing my assets, from this:



   <img src="{{ url("storage/a_inline_image.png") }}" />


To this:



   <img src="{{ asset("storage/a_inline_image.png") }}" />


Now it works.







share|improve this answer












share|improve this answer



share|improve this answer










answered May 17 '18 at 20:10









HCKHCK

3,60711238




3,60711238













  • for my personal reference, it would be great, to know, if it worked using asset(... without any additional packages?

    – Bart
    May 18 '18 at 23:19






  • 2





    @bart no, it didn't work. The original problem wasn't the way I referenced assets but the $message variable. Sadly, I haven't found a way to make it worked. And yes, I try what (I assume) you are suggesting but as I said, it didn't work :/

    – HCK
    May 18 '18 at 23:56











  • thanks for update :)

    – Bart
    May 19 '18 at 17:47



















  • for my personal reference, it would be great, to know, if it worked using asset(... without any additional packages?

    – Bart
    May 18 '18 at 23:19






  • 2





    @bart no, it didn't work. The original problem wasn't the way I referenced assets but the $message variable. Sadly, I haven't found a way to make it worked. And yes, I try what (I assume) you are suggesting but as I said, it didn't work :/

    – HCK
    May 18 '18 at 23:56











  • thanks for update :)

    – Bart
    May 19 '18 at 17:47

















for my personal reference, it would be great, to know, if it worked using asset(... without any additional packages?

– Bart
May 18 '18 at 23:19





for my personal reference, it would be great, to know, if it worked using asset(... without any additional packages?

– Bart
May 18 '18 at 23:19




2




2





@bart no, it didn't work. The original problem wasn't the way I referenced assets but the $message variable. Sadly, I haven't found a way to make it worked. And yes, I try what (I assume) you are suggesting but as I said, it didn't work :/

– HCK
May 18 '18 at 23:56





@bart no, it didn't work. The original problem wasn't the way I referenced assets but the $message variable. Sadly, I haven't found a way to make it worked. And yes, I try what (I assume) you are suggesting but as I said, it didn't work :/

– HCK
May 18 '18 at 23:56













thanks for update :)

– Bart
May 19 '18 at 17:47





thanks for update :)

– Bart
May 19 '18 at 17:47













1
















if you can use like this than it can be work other wise you don't use $message variable in mail blade



Mail::send('emails.welcome', $data, function ($message) {
$message->from('us@example.com', 'Laravel');
$message->to('foo@example.com')->cc('bar@example.com');
});


if you don't want use this method than you can use like this



https://code.tutsplus.com/tutorials/how-to-send-emails-in-laravel--cms-30046



it can be work like this.






share|improve this answer


























  • The documentations says this: "Laravel automatically makes the $message variable available to all of your email templates" so it should be available.

    – HCK
    May 13 '18 at 22:52
















1
















if you can use like this than it can be work other wise you don't use $message variable in mail blade



Mail::send('emails.welcome', $data, function ($message) {
$message->from('us@example.com', 'Laravel');
$message->to('foo@example.com')->cc('bar@example.com');
});


if you don't want use this method than you can use like this



https://code.tutsplus.com/tutorials/how-to-send-emails-in-laravel--cms-30046



it can be work like this.






share|improve this answer


























  • The documentations says this: "Laravel automatically makes the $message variable available to all of your email templates" so it should be available.

    – HCK
    May 13 '18 at 22:52














1












1








1









if you can use like this than it can be work other wise you don't use $message variable in mail blade



Mail::send('emails.welcome', $data, function ($message) {
$message->from('us@example.com', 'Laravel');
$message->to('foo@example.com')->cc('bar@example.com');
});


if you don't want use this method than you can use like this



https://code.tutsplus.com/tutorials/how-to-send-emails-in-laravel--cms-30046



it can be work like this.






share|improve this answer

















if you can use like this than it can be work other wise you don't use $message variable in mail blade



Mail::send('emails.welcome', $data, function ($message) {
$message->from('us@example.com', 'Laravel');
$message->to('foo@example.com')->cc('bar@example.com');
});


if you don't want use this method than you can use like this



https://code.tutsplus.com/tutorials/how-to-send-emails-in-laravel--cms-30046



it can be work like this.







share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 29 '18 at 19:41









HCK

3,60711238




3,60711238










answered May 13 '18 at 11:33









Keval MangukiyaKeval Mangukiya

1871313




1871313













  • The documentations says this: "Laravel automatically makes the $message variable available to all of your email templates" so it should be available.

    – HCK
    May 13 '18 at 22:52



















  • The documentations says this: "Laravel automatically makes the $message variable available to all of your email templates" so it should be available.

    – HCK
    May 13 '18 at 22:52

















The documentations says this: "Laravel automatically makes the $message variable available to all of your email templates" so it should be available.

– HCK
May 13 '18 at 22:52





The documentations says this: "Laravel automatically makes the $message variable available to all of your email templates" so it should be available.

– HCK
May 13 '18 at 22:52











1
















In my case (Larvel 5.5), I've managed, to modify header logo, in both html and markdown.



Laravel documentation, although really great, could be better in this regard.



Anyway, follow these steps, and you should be fine...



1 - Publish mail templates via:



php artisan vendor:publish --tag=laravel-mail


so you can easily modify your mail source files.



2 - Modify message.blade.php in resources/views/vendor/mail/html with this:



@slot('header')
@component('mail::header', ['url' => config('app.url')])
<img src="{{asset('assets/img/pathToYourImage...')}}">
@endcomponent
@endslot


3 - All your emails should receive logo via CID from now.



Note:



In this example Laravel, automatically converts assets to CIDs, so you don't need to call $message->embed(... at all...



Please test extensively, with these html/markdown directories and blade directives going on. It is kinda tricky, but it definitely, does its magic...






share|improve this answer


























  • My laravel 5.5 is not changing the URL for a CID id, it's just sending the url.

    – Don Viegues
    Aug 10 '18 at 19:12











  • @DonViegues are you sure you are using asset() function? If that's the case.maybe you should try package suggested by HCK in this thread - Laravel Mail Auto Embed.. BTW I believe this is a bug, and I hope it was fixed in Laravel 5.6. Can you verify that?

    – Bart
    Aug 11 '18 at 0:43











  • Hi, yes, I'm using asset(), it seems that the package you said is the way to go. thanks.

    – Don Viegues
    Aug 16 '18 at 20:35
















1
















In my case (Larvel 5.5), I've managed, to modify header logo, in both html and markdown.



Laravel documentation, although really great, could be better in this regard.



Anyway, follow these steps, and you should be fine...



1 - Publish mail templates via:



php artisan vendor:publish --tag=laravel-mail


so you can easily modify your mail source files.



2 - Modify message.blade.php in resources/views/vendor/mail/html with this:



@slot('header')
@component('mail::header', ['url' => config('app.url')])
<img src="{{asset('assets/img/pathToYourImage...')}}">
@endcomponent
@endslot


3 - All your emails should receive logo via CID from now.



Note:



In this example Laravel, automatically converts assets to CIDs, so you don't need to call $message->embed(... at all...



Please test extensively, with these html/markdown directories and blade directives going on. It is kinda tricky, but it definitely, does its magic...






share|improve this answer


























  • My laravel 5.5 is not changing the URL for a CID id, it's just sending the url.

    – Don Viegues
    Aug 10 '18 at 19:12











  • @DonViegues are you sure you are using asset() function? If that's the case.maybe you should try package suggested by HCK in this thread - Laravel Mail Auto Embed.. BTW I believe this is a bug, and I hope it was fixed in Laravel 5.6. Can you verify that?

    – Bart
    Aug 11 '18 at 0:43











  • Hi, yes, I'm using asset(), it seems that the package you said is the way to go. thanks.

    – Don Viegues
    Aug 16 '18 at 20:35














1












1








1









In my case (Larvel 5.5), I've managed, to modify header logo, in both html and markdown.



Laravel documentation, although really great, could be better in this regard.



Anyway, follow these steps, and you should be fine...



1 - Publish mail templates via:



php artisan vendor:publish --tag=laravel-mail


so you can easily modify your mail source files.



2 - Modify message.blade.php in resources/views/vendor/mail/html with this:



@slot('header')
@component('mail::header', ['url' => config('app.url')])
<img src="{{asset('assets/img/pathToYourImage...')}}">
@endcomponent
@endslot


3 - All your emails should receive logo via CID from now.



Note:



In this example Laravel, automatically converts assets to CIDs, so you don't need to call $message->embed(... at all...



Please test extensively, with these html/markdown directories and blade directives going on. It is kinda tricky, but it definitely, does its magic...






share|improve this answer

















In my case (Larvel 5.5), I've managed, to modify header logo, in both html and markdown.



Laravel documentation, although really great, could be better in this regard.



Anyway, follow these steps, and you should be fine...



1 - Publish mail templates via:



php artisan vendor:publish --tag=laravel-mail


so you can easily modify your mail source files.



2 - Modify message.blade.php in resources/views/vendor/mail/html with this:



@slot('header')
@component('mail::header', ['url' => config('app.url')])
<img src="{{asset('assets/img/pathToYourImage...')}}">
@endcomponent
@endslot


3 - All your emails should receive logo via CID from now.



Note:



In this example Laravel, automatically converts assets to CIDs, so you don't need to call $message->embed(... at all...



Please test extensively, with these html/markdown directories and blade directives going on. It is kinda tricky, but it definitely, does its magic...







share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 29 '18 at 19:42









HCK

3,60711238




3,60711238










answered May 13 '18 at 23:22









BartBart

984622




984622













  • My laravel 5.5 is not changing the URL for a CID id, it's just sending the url.

    – Don Viegues
    Aug 10 '18 at 19:12











  • @DonViegues are you sure you are using asset() function? If that's the case.maybe you should try package suggested by HCK in this thread - Laravel Mail Auto Embed.. BTW I believe this is a bug, and I hope it was fixed in Laravel 5.6. Can you verify that?

    – Bart
    Aug 11 '18 at 0:43











  • Hi, yes, I'm using asset(), it seems that the package you said is the way to go. thanks.

    – Don Viegues
    Aug 16 '18 at 20:35



















  • My laravel 5.5 is not changing the URL for a CID id, it's just sending the url.

    – Don Viegues
    Aug 10 '18 at 19:12











  • @DonViegues are you sure you are using asset() function? If that's the case.maybe you should try package suggested by HCK in this thread - Laravel Mail Auto Embed.. BTW I believe this is a bug, and I hope it was fixed in Laravel 5.6. Can you verify that?

    – Bart
    Aug 11 '18 at 0:43











  • Hi, yes, I'm using asset(), it seems that the package you said is the way to go. thanks.

    – Don Viegues
    Aug 16 '18 at 20:35

















My laravel 5.5 is not changing the URL for a CID id, it's just sending the url.

– Don Viegues
Aug 10 '18 at 19:12





My laravel 5.5 is not changing the URL for a CID id, it's just sending the url.

– Don Viegues
Aug 10 '18 at 19:12













@DonViegues are you sure you are using asset() function? If that's the case.maybe you should try package suggested by HCK in this thread - Laravel Mail Auto Embed.. BTW I believe this is a bug, and I hope it was fixed in Laravel 5.6. Can you verify that?

– Bart
Aug 11 '18 at 0:43





@DonViegues are you sure you are using asset() function? If that's the case.maybe you should try package suggested by HCK in this thread - Laravel Mail Auto Embed.. BTW I believe this is a bug, and I hope it was fixed in Laravel 5.6. Can you verify that?

– Bart
Aug 11 '18 at 0:43













Hi, yes, I'm using asset(), it seems that the package you said is the way to go. thanks.

– Don Viegues
Aug 16 '18 at 20:35





Hi, yes, I'm using asset(), it seems that the package you said is the way to go. thanks.

– Don Viegues
Aug 16 '18 at 20:35











1














You have to define the File Path Variable in your Mailable as public property -> example $pathToFile.



If you have the file path from outside of the mailable you can pass in with the constructor.



class NewUserWelcomeEmail extends Mailable
{
use SerializesModels;

// Must be public
public $pathToFile;

/**
* Create a new message instance.
*/
public function __construct(string $pathToFile)
{
$this->pathToFile= $pathToFile;
}

public function build()
{
return $this->view('mails.new_user_welcome');
}
}


Then it works as expected in your view like this:



@extends('layouts.mail')

@section('content')

<img src="{{ $message->embed(url($pathToFile)) }}" alt="An inline image" />

@endsection





share|improve this answer


























  • The problem is the $message variable not the ones flagged as public in the Mailable class.

    – HCK
    May 15 '18 at 6:06













  • oh I see, could have read better.

    – ndberg
    May 15 '18 at 6:10











  • Don't worry, I solved the issue with a workaround.. I'll update it tomorrow. Thanks anyway, mate.

    – HCK
    May 15 '18 at 6:11
















1














You have to define the File Path Variable in your Mailable as public property -> example $pathToFile.



If you have the file path from outside of the mailable you can pass in with the constructor.



class NewUserWelcomeEmail extends Mailable
{
use SerializesModels;

// Must be public
public $pathToFile;

/**
* Create a new message instance.
*/
public function __construct(string $pathToFile)
{
$this->pathToFile= $pathToFile;
}

public function build()
{
return $this->view('mails.new_user_welcome');
}
}


Then it works as expected in your view like this:



@extends('layouts.mail')

@section('content')

<img src="{{ $message->embed(url($pathToFile)) }}" alt="An inline image" />

@endsection





share|improve this answer


























  • The problem is the $message variable not the ones flagged as public in the Mailable class.

    – HCK
    May 15 '18 at 6:06













  • oh I see, could have read better.

    – ndberg
    May 15 '18 at 6:10











  • Don't worry, I solved the issue with a workaround.. I'll update it tomorrow. Thanks anyway, mate.

    – HCK
    May 15 '18 at 6:11














1












1








1







You have to define the File Path Variable in your Mailable as public property -> example $pathToFile.



If you have the file path from outside of the mailable you can pass in with the constructor.



class NewUserWelcomeEmail extends Mailable
{
use SerializesModels;

// Must be public
public $pathToFile;

/**
* Create a new message instance.
*/
public function __construct(string $pathToFile)
{
$this->pathToFile= $pathToFile;
}

public function build()
{
return $this->view('mails.new_user_welcome');
}
}


Then it works as expected in your view like this:



@extends('layouts.mail')

@section('content')

<img src="{{ $message->embed(url($pathToFile)) }}" alt="An inline image" />

@endsection





share|improve this answer















You have to define the File Path Variable in your Mailable as public property -> example $pathToFile.



If you have the file path from outside of the mailable you can pass in with the constructor.



class NewUserWelcomeEmail extends Mailable
{
use SerializesModels;

// Must be public
public $pathToFile;

/**
* Create a new message instance.
*/
public function __construct(string $pathToFile)
{
$this->pathToFile= $pathToFile;
}

public function build()
{
return $this->view('mails.new_user_welcome');
}
}


Then it works as expected in your view like this:



@extends('layouts.mail')

@section('content')

<img src="{{ $message->embed(url($pathToFile)) }}" alt="An inline image" />

@endsection






share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 29 '18 at 19:43









HCK

3,60711238




3,60711238










answered May 15 '18 at 6:04









ndbergndberg

373212




373212













  • The problem is the $message variable not the ones flagged as public in the Mailable class.

    – HCK
    May 15 '18 at 6:06













  • oh I see, could have read better.

    – ndberg
    May 15 '18 at 6:10











  • Don't worry, I solved the issue with a workaround.. I'll update it tomorrow. Thanks anyway, mate.

    – HCK
    May 15 '18 at 6:11



















  • The problem is the $message variable not the ones flagged as public in the Mailable class.

    – HCK
    May 15 '18 at 6:06













  • oh I see, could have read better.

    – ndberg
    May 15 '18 at 6:10











  • Don't worry, I solved the issue with a workaround.. I'll update it tomorrow. Thanks anyway, mate.

    – HCK
    May 15 '18 at 6:11

















The problem is the $message variable not the ones flagged as public in the Mailable class.

– HCK
May 15 '18 at 6:06







The problem is the $message variable not the ones flagged as public in the Mailable class.

– HCK
May 15 '18 at 6:06















oh I see, could have read better.

– ndberg
May 15 '18 at 6:10





oh I see, could have read better.

– ndberg
May 15 '18 at 6:10













Don't worry, I solved the issue with a workaround.. I'll update it tomorrow. Thanks anyway, mate.

– HCK
May 15 '18 at 6:11





Don't worry, I solved the issue with a workaround.. I'll update it tomorrow. Thanks anyway, mate.

– HCK
May 15 '18 at 6:11


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50248498%2fnot-receiving-the-message-variable-in-view-from-a-laravel-html-mailable-non-ma%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine