为什么电子邮件验证功能没有正确获取收件人地址


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 函数时,它给出了一个错误,即未定义的变量:输入。为什么会这样?提前感谢

变量输入不在匿名函数的作用域内。 请使用如下所示的"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