我在laravel中收到了$ recipient变量未定义的错误。
public function sendEmail($input, $recipients){
foreach($recipients as $recipient){
$student = StudentInfo::where('email', '=', $recipient)->first();
Mail::queue('emails.outMail', array('letter' => $input['dept_message']), function($message){
$message->to($recipient, $student->first_name)->subject($input['dept_subject']);
});
}
}
答案 0 :(得分:-1)
在闭包功能中,您需要使用$ recipient。
function($message) use ($recipient){
//code
}
更新代码
public function sendEmail($input, $recipients){
foreach($recipients as $recipient){
$student = StudentInfo::where('email', '=', $recipient)->first();
Mail::queue('emails.outMail', array('letter' => $input['dept_message']), function($message) use ($recipient) {
$message->to($recipient, $student->first_name)->subject($input['dept_subject']);
});
}
}