snowfire / Beautymail

Send beautiful HTML emails with Laravel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing data to email template

msalehipro opened this issue · comments

How can i pass data from controller to my email view ?
if it's possible, show me some sample code.

Hi @ghambale

Just call the element of the data directly i.e.

$mailData = [
  'user' => '', // some data,
  'token' => ''
]

$beautymail = app()->make(Beautymail::class);
$beautymail->send('emails.welcome', $mailData, function ($message) {
  $message
  ->from('yourmail@yoursite.com') // or leaving it blank makes use of MAIL_FROM_ADDRESS and MAIL_FROM_NAME in env
  ->to($mailData->user->email, $mailData->user->fullName())
  ->subject('Welcome!');
});

Then in the mail blade file.

<p>Hi, {{$user->first_name}}<p>

See how I used the user property directly instead of $mailData->user->first_name // This will not work