Embedding image in laravel markdown email - php

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?

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

php email image not display in gmail

I want to display image in email that send from php. In yahoo the image was display but in gmail the image is missing.
This is the code for display image
<img alt="" data-pyroimage="true" src="{{ url:site }}image/sample.png" style="width:66%;" />
This is the image url after i inspect in gmail
<img alt="" src="https://ci5.googleusercontent.com/proxy/KaJG60d7WUoIwstJlDYAp8vLq1SSpmWyOZlrgZtUJMtHoBCEr863637_4tdJaibPlgJy7jnzXHs5RGv8C3g=s0-d-e1-ft#http://ipaddress/image/sample.png" style="width:66%" class="CToWUd">
I would suggest using the img plugin function to reveal a physical file location. If that's an image in the public directory something like this might work:
{{ img('public::image/sample.png').url }}
Then you can bet that Google will treat it much like a native image source.

Laravel 5.4 mail messages how to edit header and footer

Hi I am trying to use MailMessage function in my Laravel App. My question is very simple. How to edit the Header and the Footer when receiving email from the app? Here is the picture below.
I want to change the header Laravel from my App name and the Hello with a Hello $user->name and the Regards, with my App name also and the footer below to the App name also.
I tried to change the `
resources/views/vendor/mail/markdown/message.blade.php
To:
#component('mail::layout')
{{-- Header --}}
#slot('header')
#component('mail::header', ['url' => config('app.url')])
CCTV App
#endcomponent
#endslot
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
#isset($subcopy)
#slot('subcopy')
#component('mail::subcopy')
CCTV Team
#endcomponent
#endslot
#endisset
{{-- Footer --}}
#slot('footer')
#component('mail::footer')
© {{ date('Y') }} CCV3. All rights reserved.
#endcomponent
#endslot
#endcomponent
But not working when I send a reset password request
Would really appreciate if someone can help me.
Thanks in advance.
`
I want to change the header Laravel from my App name and the Hello with a Hello $user->name and the Regards, with my App name also and the footer below to the App name also
Mailable Markdown by default has the config('app.name') that picks the APP_NAME from your .env file. So by modifying the APP_NAME will effect on your markdown template.
OR if you modifying it manually, run the following command on your terminal
php artisan vendor:publish --tag=laravel-mail and go to the resources/views/vendor/mail/html/message.blade.php and modify the header and footer slot.
For changing Hello to Hello {user_name}, there is markdown called greeting() method that holds Hello!, you can change it whatever you want.
For Regards run this command on your terminal
php artisan vendor:publish --tag=laravel-notifications and go to the resources/views/vendor/notifications/email.blade.php and modify the Regards whatever you want.
To know more in details take a look on customizing markdown email.
I already figure it out just change the name of the env file to your App name instead of laravel. This is the sample below.
APP_NAME=Laravel
Change it to
APP_NAME=YOUR_APP_NAME
there is also one way to edit your mail template.
Just go to resources/views/vendor/notifications/email.blade.php
and you can also edit the message to your mail just go to resources/views/vendor/markdown/message.blade.php
You are using default component for your email template named #component('mail::message'), It does not allow you to modify header. But if you go to the file of this component,
\vendor\laravel\framework\src\Illuminate\Mail\resources\views\markdown\message.blade.php
you will notice that it uses another component #component('mail::layout'),
Just copy content of message.blade.php file into your .blade.php and replace {{ $slot }} with what you had in your file before.
And you are done.

Img not displaying correctly in Symfony

My twig file goes like this :
Let us try to see an image :
<img src="{{ absolute_url(asset('app/Resources/images/bulb.png')) }}" alt="Symfony!" width="42" height="42"/>
Trying it another way :
<img src="app/Resources/images/bulb.png" alt="Symfony!" width="42" height="42"/>
But when I go to that page in Symfony, I see something like this :
What did I do wrong ?
currently, twig is going to be trying to find your asset in:
/web/app/Resources/images/bulb.png
use instead:
{{ asset('#AppBundle/Resources/public/images/bulb.png', absolute=true) }}
note the use of an additional public folder. If you must store assets in app, then this is sensible.
However, #Ewan Delanoy is correct, you really should be storing all your assets directly in the web folder.
Then you can just call
{{ asset('images/bulb.png', absolute=true) }}

Is it possible to include an image in a HTML email in Laravel

I'm currently trying to send an HTML email via Laravel's Mail::send(). The view in which I'm using is a Blade template, but I'm not quite sure on how I would go about including an image in the body of the email.
In my template, I have
<h4>You have successfully updated your Session!</h4>
#if ( $old_date != $date)
<p>You have changed from {{ $old_date }} to {{ $date }}</p>
#endif
<p>If you have any questions or concerns, please contact the Office of Admissions</p>
{{ HTML::image('/images/full-logo.png', 'logo') }}
However, my email comes out with just a broken link icon in the body of the email. Is it possible to pass an image as a parameter to the view? In my Controller which sends the email, I have
$data = array (
'first_name' => $student->first_name,
'last_name' => $student->last_name,
'date' => $day,
'old_date' => $old_day,
);
Mail::send ( '/emails/create_student', $data, function ($message) {
...
} );
So I'm not sure if it might be possible to include an image via the $data array.
This one worked for me:
The image is declared in the email view
<img src="{{ $message->embed(public_path() . '/resources/icon/icon.png') }}" alt="" />
from Laravel doc
"A $message variable is always passed to e-mail views, and allows the inline embedding of attachments."
HTML::image() generates absolute path to image, like this:
http://yoursite.dev/image.png
which works perfectly in your local environment.
Mail client, as Gmail, will override image path with something like this:
http://images.gmail.com/?src=http://yoursite.dev/image.png
Obviosly 3rd party service can't access your local domain and so you see broken image.
As a solution, you can upload images to 3rd party service like Amazon AWS and pass link to uploaded image to email template.

Passing Assetic image path from database

I have been stumped for a couple days and I am seeking some direction.
I am attempting to call an image path stored in database to twig file in order to display said image. The twig example below, I am expecting the same image to be displayed twice. When inspecting the rendered html, the variable passes the path from the database, but the first image is not displayed.
From controller:
'logo' => $vendor->getLogovendors()
From database column logoVendors:
<img src={{asset('bundles/loginlogin/img/fs_logo_large.png')}} />
From twig:
<div class="container">
{{logo | raw}}
<img src={{asset('bundles/loginlogin/img/fs_logo_large.png')}} />
</div>
I am new to Symfony and its asset management. Any help or prodding in the right direction would be appreciated.
You should normally store only the path to the image in your database!
If logo was the variable you pass to the template holding the image path bundles/loginlogin/img/fs_logo_large.png you could simply include it using twig's asset function like this:
<img src="{{ asset(logo) }}"/>
what you're trying to do ( evaluating a twig function inside a string ) can be solved aswell...but i don't recommend it.
If you want to store the complete code including {{ asset() }} in your database you need to make twig evaluate the code inside the string.
This means twig shall execute the code inside the string instead of just printing it.
This can be achieved using the evaluate filter from this answer.
The final result would then be:
{{ logo |evaluate |raw }}

Categories