My code to send email like this :
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Test')
->markdown('vendor.mail.markdown.message', ['data' => $this->data]);
}
My message.blade view like this :
#component('mail::layout')
{{-- Header --}}
#slot('header')
#component('mail::header', ['url' => config('app.url')])
{{ config('app.name') }}
#endcomponent
#endslot
{{-- Body --}}
This is your logo
![Some option text][logo]
[logo]: {{asset('img/my-logo.png')}} "Logo"
{{-- Subcopy --}}
#isset($subcopy)
#slot('subcopy')
#component('mail::subcopy')
{{ $subcopy }}
#endcomponent
#endslot
#endisset
{{-- Footer --}}
#slot('footer')
#component('mail::footer')
© {{ date('Y') }} {{ config('app.name') }}. All rights reserved.
#endcomponent
#endslot
#endcomponent
It success send email, but the contain of email like this :
This is your logo
![Some option text][logo]
[logo]: http://myshop.dev/img/my-logo.png "Logo"
The image not display
How can I solve this problem?
I follow this reference : https://medium.com/#adnanxteam/how-to-customize-laravel-5-4-notification-email-templates-header-and-footer-158b1c7cc1c
This worked for me !
<img src="{{$message->embed(asset('images/image_name.png'))}}">
for those who have Undefined variable: message :
you need to send the variable $message to the view, while $message is the Mailable instance.
example:
$this->view('view_name_here')
->with(['message' => $this])
->subject("Hello..");
This is an old question but this might help someone else. Try this... (assuming you want to replace the app name with your logo)
#component('mail::layout')
{{-- Header --}}
#slot('header')
#component('mail::header', ['url' => config('app.url')])
<img src="{{ asset('img/my-logo.png') }}" alt="{{ config('app.name') }} Logo">
#endcomponent
#endslot
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
#isset($subcopy)
#slot('subcopy')
#component('mail::subcopy')
{{ $subcopy }}
#endcomponent
#endslot
#endisset
{{-- Footer --}}
#slot('footer')
#component('mail::footer')
© {{ date('Y') }} {{ config('app.name') }}. #lang('All rights reserved.')
#endcomponent
#endslot
#endcomponent
When you extend 'vendor.mail.markdown.message' you explicitly say that the rendered mail will use this view only, which is markdown, and you completely ignore the HTML email that'll be sent.
Markdown emails have an HTML version and a raw text version, you don't see the changes you made to the markdown files because you're looking at the HTML version of your email, so see those changes you have to update /resources/views/vendor/mail/html/message.blade.php not only the markdown one.
#component('mail::layout')
{{-- Header --}}
#slot('header')
#component('mail::header', ['url' => config('app.url')])
{{ config('app.name') }}
#endcomponent
#endslot
{{-- Body --}}
This is your logo
![Some option text][logo]
[logo]: <img src="{{url('/img/my-logo.png')}}" style="height: 100px;"/> "Logo"
{{-- Subcopy --}}
#isset($subcopy)
#slot('subcopy')
#component('mail::subcopy')
{{ $subcopy }}
#endcomponent
#endslot
#endisset
{{-- Footer --}}
#slot('footer')
#component('mail::footer')
© {{ date('Y') }} {{ config('app.name') }}. All rights reserved.
#endcomponent
#endslot
#endcomponent
See I have added an tag where your image should be. The url('/img/my-logo.png') converts to your full site address where the image is stored.
Try to output the image inside an <img> tag:
<img src="{{ $message->embed(asset('img/my-logo.png')) }}" alt="alt here">
Related
I am trying to replace the app name in a Laravel markdown email header with an image but I am not having a lot of success.
message.blade.php
#component('mail::layout')
{{-- Header --}}
#slot('header')
#component('mail::header', ['url' => config('app.url')])
#if(config('app.site.logo'))
<img src="{{ url(config('app.site.logo')) }}" class="site-
logo" height="50" />
#else
{{ config('app.site.name', 'Campaign') }}
#endif
#endcomponent
#endslot
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
#isset($subcopy)
#slot('subcopy')
#component('mail::subcopy')
{{ $subcopy }}
#endcomponent
#endslot
#endisset
{{-- Footer --}}
#slot('footer')
#component('mail::footer')
© {{ date('Y') }} {{ config('app.site.name', 'Campaign') }}.
#lang('All rights reserved.')
#endcomponent
#endslot
#endcomponent
followup.blade.php <-- email markdown page
#component('mail::message')
## Follow up reminder
Set for today {{ date('l \t\h\e jS \of F Y', strtotime($member->FollowUp)) }} with {{$member->LastName}} {{$member->FirstName}} / {{$member->Position}}
#component('mail::panel', ['url' => ''])
#if(count($member->notes))
*notes...*
#foreach($member->notes->sortByDesc("created_at") as $note)
**{!! nl2br(e($note->note)) !!}**
by *{{$note->user->name}}.*
#endforeach
#else
No notes added for member
#endif
#endcomponent
Probable Vote: {{$member->LikelyVote}}
#component('mail::button', ['url' => $the_url])
View Information
#endcomponent
Thank you,
{{ config('app.site.name', 'Campaign application A.I.') }}
#endcomponent
Everything works on mailtrap and the header image shows up. The image does not show up in gmail.
Original Question - How to get rid of "Laravel" in the header
Set the App Name
In your .env set the
APP_NAME="YOUR APPLICATIONS NAME"
Which is where the Laravel in the header is coming from.
Or Modify the Template
You can have more control by publishing the source for the markdown mailables by running:
php artisan vendor:publish --tag=laravel-mail
And editing them at resources/views/vendor/mail
Images
The way to include images from your server is:
![Some option text][logo]
[logo]: {{asset('/img/official_logo.png')}} "Logo"
Otherwise, you can get the base64 encoding and drop that into an img tag to truely embed the image (after reading it into a variable (image)):
<img src="data:image/jpg;base64,{{ base64_encode($image) }}">
I'm trying to remove the header part from laravel's markdown template but it's not working, I published the files into my vendor folder and all.
This is my message component:
#component('mail::layout')
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
#isset($subcopy)
#slot('subcopy')
#component('mail::subcopy')
{{ $subcopy }}
#endcomponent
#endslot
#endisset
{{-- Footer --}}
#slot('footer')
#component('mail::footer')
© {{ date('Y') }} {{ env('APP_NAME') }}.
#endcomponent
#endslot
#endcomponent
And my layout file:
{!! strip_tags($slot) !!}
#isset($subcopy)
{!! strip_tags($subcopy) !!}
#endisset
{!! strip_tags($footer) !!}
Any help?
Also, is it possible to make my own markdown template without using default layout? I tried adding laravel markdown components directly into my mail blade.php files but everything lookied like trash and uncentered.
Thanks in advance.
Using change mark down template
You need to fire php artisan vendor:publish --tag=laravel-mail command on project root using terminal
After executed above command, generate some blade file on below path: resources/views/vendor/mail/html
Remove code from header.blade.php.
Using custom mail template
Also you can send mail using custom mail template. see below code.
Mail::send([YOUR TEMPLATE], [DATA], function ($m) use ($user) {
$m->from('[FROM_MAIL]',[FROM_NAME]);
$m->to([TO_EMAIL])->subject([SUBJECT]);
});
In some applications, I have very small blade templates that I only use in one single template.
Unfortunately I still need to create a separated file such as:
Component jumbotron:
<div class="jumbotron">
<h1 class="display-4">{{ $title }}</h1>
{{ $slot }}
</div>
In my main component I then use:
#component('jumbotron', ['title' => 'Foo'])
Hello World!
#endcomponent
I would like to find a way to embed my component in my template such as:
#template('jumbotron')
<div class="jumbotron">
<h1 class="display-4">{{ $title }}</h1>
{{ $slot }}
</div>
#endtemplate
#component('jumbotron', ['title' => 'Foo'])
Hello World!
#endcomponent
I this somehow possible?
How I can send email with default template, have a $data params in body?
My code:
Mail::send('vendor.mail.html.message', $data, function($message) use($data) {
$message->to($data['email']);
$message->subject('New notification');
});
Default email template:
#component('mail::layout')
{{-- Header --}}
#slot('header')
#component('mail::header', ['url' => config('app.url')])
{{ config('app.name') }}
#endcomponent
#endslot
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
#isset($subcopy)
#slot('subcopy')
#component('mail::subcopy')
{{ $subcopy }}
#endcomponent
#endslot
#endisset
{{-- Footer --}}
#slot('footer')
#component('mail::footer')
© {{ date('Y') }} {{ config('app.name') }}. All rights reserved.
#endcomponent
#endslot
#endcomponent
I send $data params. How I can add this params on default email template without edit email template?
Define your variable like this
$data['slot']= "hello world";
$data['subcopy']= "Your Copy";
$data['email']= "email#email.com";
Mail::send('vendor.mail.html.message', $data, function($message) use($data) {
$message->to($data['email']);
$message->subject('New notification');
});
My LoginUser.blade.php
<h1>Login</h1>
{{-- Form start comment --}}
{{ Form::open(array('url' => 'user/loginUser')) }}
<p>
{{ Form::label('email', 'E-Mail Address') }}
{{ Form::email('email', null, array("placeholder" => "Enter your email")) }}
</p>
<p>
{{ Form::label('password', 'Password') }}
{{ Form::password('password', array("placeholder"=>"Enter your password")) }}
</p>
<p>
{{ Form::submit('Sign In') }}
</p>
{{ Form::close() }}
{{-- Form end comment --}}
So my Question is why should my URL points to my current LoginUser.blade.php which contains the HTML forms?? Please am new to laravel am using laravel 5.2