0

Im getting undefined variable errors when trying to insert a bcc list and names.

  $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('[email protected]', 'All Users')
            ->bcc("$bcclist", "$bccnamelist")
            ->subject(Input::get('emailsubject'));
   });

How can I do what I want here?

1 Answer 1

3

This is a variable scope issue. You have to add $bcclist and $bccnamelist to use():

Mail::send('emails.buildsoftheweek', $data, function($message) use ($email, $bcclist, $bccnamelist){
$message->to('[email protected]', 'All Users')
        ->bcc("$bcclist", "$bccnamelist")
        ->subject(Input::get('emailsubject'));
});

Also there's no need to put those variables in a string. This should work as well:

->bcc($bcclist, $bccnamelist)
Sign up to request clarification or add additional context in comments.

2 Comments

Oh easy enough! Thanks :)
@user2921557 : If the answer helps you. You shall accept the answer by marking the Ticket Icon to the left side of the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.