I am using Laravel's mail class and would like to pass variable into subject. Here is my code:
public function send()
{
$offer = Offer::find($id)->toArray();
Mail::send('offerMail', $offer, function($message) {
$message->to('[email protected]');
$message->subject('Offer No.' . $offer['code']);
});
}
I am getting
Undefined variable: offer
within line where subject is defined.
Don't forget to inject your outer variables into Closure's scope.
Mail::send('offerMail', $offer, function($message) use ($offer) {
$message->to('[email protected]');
$message->subject('Offer No.' . $offer['code']);
});
You can see examples about this under Example 3 section in here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With