【发布时间】:2015-10-09 19:31:11
【问题描述】:
我有一系列电子邮件需要在 Laravel 4.2 中发送消息。这个数组是
$email_arr = ["me@yahoo.com","friend@gmail.com"]
现在我的逻辑是简单地遍历电子邮件数组并向每个人发送一条消息,如下所示:
foreach($email_arr as $email){
Mail::send('emails.invite', array('pool_code' => 'test'), function($message) {
$message->to($email)->subject('Join my capture pool!');
});
}
但是,我收到一个指向 $message->to($email)->subject('Join my capture pool!'); 的错误,上面写着 Undefined variable: email。
我觉得这很奇怪,因为变量显然存在,如果我在循环中 echo $email 它会正确打印出每封电子邮件。
那么这里发生了什么?
【问题讨论】: