PHP Laravel 5 用户 class 属性在创建帐户后无法发送电子邮件

PHP Laravel 5 User class properties not accessible for sending Email after account creation

我有一个问题,我无法将变量放入 laravel 中的 Mail::send() 函数中。请看以下代码:

$first_name = $request->input('first_name'),
$email = $request->input('email'),

//Create account

User::create([
    'first_name' => $first_name,
    'last_name' => $request->input('last_name'),
    'email' => $email,
    'password' => bcrypt($request->input('password')),
]);

//Send email to user

Mail::send('emails.test', ['fname' => $first_name], function($message)
{
    $message->to($email)
            ->subject('Welcome!');
});

return redirect()
    ->route('home')
    ->with('info', 'Your account has been created and an authentication link has been sent to the email address that you provided. Please go to your email inbox and click on the link in order to complete the registration.');

由于某种原因,代码在发送电子邮件时中断,因为我收到错误并将数据发送到数据库。为什么此后无法再访问该变量?

如有任何帮助,我们将不胜感激。谢谢

Closures may also inherit variables from the parent scope. Any such variables must be passed to the use language construct.

来源:http://php.net/manual/en/functions.anonymous.php

也就是说,$email要这样继承:

Mail::send('emails.test', ['fname' => $first_name], function($message) use ($email)
{
    $message->to($email)
            ->subject('Welcome!');
});

注:第一行use ($email)