邮箱验证功能为什么收件人地址不正确?

Why email verification function not taking the to address properly?

这是我的职能。

public function email_verify_send_mail()
    {
        $inputs = \Input::all();
        $rules = array(
            'email' => 'required|email'
        );
         $validation = Validator::make($inputs, $rules);

        if ($validation->fails()) {
            $messages = $validation->errors();
            return View::make('email_verify')->with('errors', $messages);
        }
        else{
            $in=$inputs['email'];
            //send mail to the user.......
            Mail::send('email_view', ['key' => 'value'], function($message)
            {
                $message->to($inputs['email'])->subject('Welcome!');
            });
            return "okie";


        }
    }

这里当我打印 $inputs['email'] 时,它清楚地打印了电子邮件地址。 但是当我将它添加到 mail::send 函数时,它给出了一个错误 Undefined variable: inputs。为什么会这样?谢谢提前

变量输入不在匿名函数的范围内。请使用如下 "use" 语句:

public function email_verify_send_mail()
{
    $inputs = \Input::all();
    $rules = array(
        'email' => 'required|email'
    );
     $validation = Validator::make($inputs, $rules);

    if ($validation->fails()) {
        $messages = $validation->errors();
        return View::make('email_verify')->with('errors', $messages);
    }
    else{
        $in=$inputs['email'];
        //send mail to the user.......
        Mail::send('email_view', ['key' => 'value'], function($message) use ($inputs)
        {
            $message->to($inputs['email'])->subject('Welcome!');
        });
        return "okie";


    }
}

试试这个....

Mail::send('email_view', ['key' => 'value'], function($message)
            {
                $message->to($inputs['email'])->subject('Welcome!');
            });

Mail::send('email_view', ['email' => $in], function($message)
            {
                $message->to($email)->subject('Welcome!');
            });

(或)

  Mail::send('email_view', function($message)  use($in)
                {
                    $message->to($in)->subject('Welcome!');
                });

参考:https://laravel.com/docs/5.0/mail