loic-sharma / Messages

A Laravel Bundle for the Swiftmailer library
GNU Lesser General Public License v3.0
39 stars 7 forks source link

Undefined variables when using view files #14

Closed theninthnode closed 11 years ago

theninthnode commented 11 years ago

I'm trying to use view files to send the emails but I'm having trouble accessing the variables passed in. Am I doing this correctly? I'm getting message in view: Undefined variable: user

Message::send(function($message) use ($user){
                $message->to($user->email);
                $message->from('billyjones25@gmail.com', 'Website name');

                $message->user = $user;

                $message->subject('Welcome!');
                $message->body('view: emails.welcome');
}); 

View:

Hi {{$user->first_name}}!

Thanks for joining ______. We listed your sign in details below, make sure you keep them safe.

Your username: {{$user->username}}
Your email address: {{$user->email}}
Password: {{$user->password}}
loic-sharma commented 11 years ago

You need to do:

$message->body->user = $user;

See if that works.

theninthnode commented 11 years ago

That works perfect! Thanks, Billy