我想将邮件发送到可变邮寄地址,我正在做的是:
$this->create($request->all()); //Send confirmation mail $email = $request['email']; Mail::send('auth.emails.welcome', ['token' => 'System'], function ($message) { $message ->to( $email, 'Laravel 5.2 App' ) ->subject('Activate Your Account !'); });
但是我收到了这个错误:
详细代码是:
public function register(Request $request) { $validator = $this->validator($request->all()); if ($validator->fails()) { $this->throwValidationException( $request, $validator ); } //Auth::login($this->create($request->all())); $this->create($request->all()); //Send confirmation mail $email = $request['email']; Mail::send('auth.emails.welcome', ['token' => 'System'], function ($message) { $message ->to( $email, 'Laravel 5.2 App' ) ->subject('Activate Your Account !'); }); return redirect($this->redirectPath()); }
有人可以帮忙吗?
您需要使用use
构造将变量传递给闭包,因为闭包具有不同的范围:
$this->create($request->all()); //Send confirmation mail $email = $request['email']; Mail::send('auth.emails.welcome', ['token' => 'System'], function ($message) use ($email) { $message->to($email,'Laravel 5.2 App') ->subject('Activate Your Account !'); });
您可以在PHP:匿名函数文档中阅读更多相关内容.