当我执行foreach()
循环时,当前数组元素的值$recipient
未定义在 line 上->to($recipient)
。为什么是这样?
PHP 代码(抛出错误)
foreach($recipients as $recipient) {
Mail::send('emails.invite', $data, function($m){
$m
->from('welcome@website.com', Auth::user()->name)
->to($recipient)
->subject('Auth::user()->name has invited you!');
});
}
错误
Notice: Undefined variable: recipient
PHP 代码(无错误)
foreach($recipients as $recipient) {
echo $recipient;
}