Tezla has pointed this out, but to bring in variables from a parent function when using Mail
you need to utilise use()
. It isn't mentioned in the docs, but it is used in the example they provide:
public function sendEmail(Request $request, $id)
{
$user = User::findOrFail($id);
Mail::send('emails.reminder', ['user' => $user], function ($m) use ($user) {
$m->from('hello@app.com', 'Your Application');
$m->to($user->email, $user->name)->subject('Your Reminder!');
});
}
In the above example, they are finding the users details with an Eloquent query and then bringing those in to the Mail
process with use()
.
In your case, you would want to format it like so:
public static function sendemail($recipient,$ticketdata)
{
Mail::send('emails.ticketbooked', $ticketdata, function ($message) use($recipient) {
$message->to($recipient)->subject('Tickets Booking Confirmation');
});
}