I have an array of emails I need to send a message to in Laravel 4.2. This array is
$email_arr = ["me@yahoo.com","friend@gmail.com"]
Now my logic is to simply iterate through the email array and send a message to each one, like so:
foreach($email_arr as $email){
Mail::send('emails.invite', array('pool_code' => 'test'), function($message) {
$message->to($email)->subject('Join my capture pool!');
});
}
However, I get an error pointing to $message->to($email)->subject('Join my capture pool!');
which says Undefined variable: email
.
I find this strange as the variable clearly exists, and if I echo $email
within the loop it prints out each email correctly.
So what's happening here?