user2274356
user2274356

Reputation: 135

Laravel problems when sending email

When I'm trying to send an email using the swiftmailer in laravel I get the folowing error: "Missing argument 2 for UsersController::{closure}()".

My code is below:

Mail::send('emails.default', array('key' => Config::get('settings.WELCOMEMAIL')), function($message, $mail, $subject = 'Welcome!')
{
    $message->to($mail)->subject($subject);
});

It's really weird though. The $mail variable contains a valid email address and I'm not using the UsersController at all in this script.

Thanks in advance

Upvotes: 2

Views: 778

Answers (1)

Damien Pirsy
Damien Pirsy

Reputation: 25435

You must pass only the $message to the closure. Any additional variable must be passed down with the use keyword:

Mail::send('emails.default', array('key' => Config::get('settings.WELCOMEMAIL')), function($message) use($mail, $subject)
{
    $subject = empty($subject) ? 'Welcome!' : $subject;
    $message->to($mail)->subject($subject);
});

Upvotes: 5

Related Questions