Pass variables inside the Mail function

Submitted by aglipanci - 2 years ago

When you need to pass some data to the Mail::send or Mail::queue, you need to make use of the "use" approach:

$data = array( 'email' => 'sample@sample.com', 'first_name' => 'Lar', 'from' => 'sample@sample.comt', 'from_name' => 'Vel' );

Mail::send( 'email.welcome', $data, function( $message ) use ($data)
{
    $message->to( $data['email'] )->from( $data['from'], $data['first_name'] )->subject( 'Welcome!' );
});
comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks