尝试插入密件抄送列表和名称时,我得到了未定义的变量错误。
$query = DB::table('users')->get();
$bcclist = "";
$bccnamelist = "";
foreach ($query as $key=>$user) {
$bcclist .= $user->email.",";
$bccnamelist .= $user->username.",";
}
$email = '';
$data = Input::all();
Mail::send('emails.buildsoftheweek', $data, function($message) use ($email){
$message->to('admin@buildsanctuary.com', 'All Users')
->bcc("$bcclist", "$bccnamelist")
->subject(Input::get('emailsubject'));
});
我怎样才能在这里做我想做的事?
答案 0 :(得分:3)
这是一个可变范围问题。您必须将$bcclist
和$bccnamelist
添加到use()
:
Mail::send('emails.buildsoftheweek', $data, function($message) use ($email, $bcclist, $bccnamelist){
$message->to('admin@buildsanctuary.com', 'All Users')
->bcc("$bcclist", "$bccnamelist")
->subject(Input::get('emailsubject'));
});
此外,无需将这些变量放在字符串中。这也应该有效:
->bcc($bcclist, $bccnamelist)