When I do a foreach() loop, the current array element's value $recipient is not defined on the line ->to($recipient). Why is this?
PHP Code (throws error)
foreach($recipients as $recipient) {
Mail::send('emails.invite', $data, function($m){
$m
->from('[email protected]', Auth::user()->name)
->to($recipient)
->subject('Auth::user()->name has invited you!');
});
}
Error
Notice: Undefined variable: recipient
PHP Code (NO error)
foreach($recipients as $recipient) {
echo $recipient;
}