将数组传递到laravel密件抄送邮件列表

时间:2015-02-20 21:21:44

标签: php email laravel laravel-4

尝试插入密件抄送列表和名称时,我得到了未定义的变量错误。

  $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'));
   });

我怎样才能在这里做我想做的事?

1 个答案:

答案 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)