0
votes

My Laravel app allows users to modify email templates, then save them to database.

Sample:

Customer {{ $customer_name }} has accepted your proposed timing {{ $timing }} for PO {{ $po_no }}

(User can change 'customer' to 'client' etc.. but leave the {{ }} intact )

The app then loads dynamic data below into above template.

$data = array('customer_email'=> "[email protected]", 'timing'=> "2pm",'po_no' => "PO001" );

Then email those rendered text to some emails.

How can I do that?

Rephrase:

  1. load text from db
  2. make it a Blade template
  3. render that template with data

I get stuck at #2

1
Can't you use View::render()? - Ravan Scafi
@Ravan, how? Laravel only accepts filed-views? - hour man
Not possible without eval() and I wouldn't wanna go down that road... - lukasgeiter
My solution so far: Save the customizable templates into view files. - hour man

1 Answers

0
votes

add email view to your views/emails folder
ex: mail_template.blade.php

Customer {{ $customer_name }} has accepted your proposed
 timing {{ $timing }} for PO {{ $po_no }}

send method

Mail::send('emails.mail_template', array('customer_email'=> "[email protected]", 'timing'=> "2pm",'po_no' => "PO001" ), function($message)
            {
                $message->to('[email protected]')->subject('your email subject');
            });

further read Official Doc