Home > Back-end >  How to send email from templates stored in database
How to send email from templates stored in database

Time:06-11

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

@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?

CodePudding user response:

Laravel 9 has this blade inline blade template rendering.

Link to documentation

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

  • Related