For some reason, the example code in the Laravel docs for their Mail feature neglect to show how to pass defined variables into the closure. Here is something a little more useful.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// note, to use $subject within your closure below you have to pass it along in the "use (…)" clause. | |
$subject = 'Welcome!'; | |
Mail::send('emails.welcome', ['key' => 'value'], function($message) use ($subject) { | |
// note: if you don't set this, it will use the defaults from config/mail.php | |
$message->from('bar@example.com', 'Sender Name'); | |
$message->to('foo@example.com', 'John Smith') | |
->subject($subject); | |
}); |