Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to send email from templates stored in database

I am trying to send email using laravel but all the email templates would be stored in the database. Then loaded when sending a new email.

here is my code

//send verification email
if(!function_exists('sendVerificationEmail')){
    function sendVerificationEmail(){
        $email_template = EmailTemplate::where('name', 'verification_mail')->first();
        $subject = $email_template->subject;
          
        $email = user('email');
        $verification_link = 'test.com';
            
        Mail::to($email)->send(new VerificationMail($email_template, $subject, $verification_link));
                
    }
}

Then here is my mail view

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@component('mail::message')

{!! html_entity_decode($email_template->body) !!}


Thanks,<br>
{{ config('app.name') }}
@endcomponent

In the database there the template

Thank you for registering, your verification link is {{$verification_link}}

However, when I send this email, it sends

Thank you for registering, your verification link is {{$verification_link}} 

Thanks,
FloralTY

How can i render the {{$verification_link}} as test.com in the body of the email?

>Solution :

Laravel 9 has this blade inline blade template rendering.

Link to documentation

https://laravel.com/docs/9.x/blade#rendering-inline-blade-templates

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading