邮件不是从ajax post请求发送laravel 5

邮件不是从ajax post请求发送laravel 5

问题描述:

I am working on forgot password functionality in my laravel 5.0 application. I am asking user to enter registered email and submit(post method) this form works on jquery ajax post request. After getting email from request i am checking it in db whether it exist or not. if exist i am updating new password, if not sending an error message upto this every this is fine. Now i am trying to send email with new password to the user, it is not working. Password is updating but email not sending.Find my controller code below

public function forgot_pass(Request $request){

        $email = $request->input('femail');
        $data = ['email' => $email];

        $user = Myuser::where($data)->count();

        if($user == 0){
            return response()->json(['status' => 'Invalid']);
        }
        else{

            $user_details = Myuser::where($data)->get()->first();

            $new_pass = $this->generateRandomString();

            $md5_pass = md5("EEE".$new_pass);

            $status = Myuser::where('email', $email)
                ->update(['pass' => $md5_pass]);

                if($status){

                    $mail_data = ['name' => $user_details->name, 'new_pass' => $new_pass];

                    Mail::send('emails.newpassword', $mail_data, function($message)
                    {
                        $message->from('us@example.com', 'Laravel');

                        $message->to($email);

                    });

                    return response()->json(['status' => 'Invalid']);
                }

        }

    }

Actually mail is working if i used $message->to('sometest@testmail.com'); instead of $message->to($email);. Below is the error i am getting.
enter image description here

Feeling strange why $email causing error.

我正在处理laravel 5.0应用程序中的忘记密码功能。 我要求用户输入注册的电子邮件并提交(发布方法)此表单适用于jquery ajax post请求。 从请求收到电子邮件后,我在db中检查它是否存在。 如果存在我正在更新新密码,如果没有向此发送错误消息,则每次都可以。 现在我正在尝试向用户发送带有新密码的电子邮件,但它无法正常工作。 密码正在更新,但是电子邮件没有发送。请在下面找到我的控制器代码
p>

  public function forgot_pass(Request $ request){
 
 $ email = $ request-&gt  ; input('femail'); 
 $ data = ['email'=>  $ email]; 
 
 $ user = Myuser :: where($ data) - > count(); 
 
 if if($ user == 0){
 return response() - > json(  ['status'=>'无效']); 
} 
其他{
 
 $ user_details = Myuser :: where($ data) - > get() - > first(); 
  
 $ new_pass = $ this-> generateRandomString(); 
 
 $ md5_pass = md5(“EEE”。$ new_pass); 
 
 $ status = Myuser :: where('email',$ email)  
  - >更新(['pass'=> $ md5_pass]); 
 
 if if($ status){
 
 $ mail_data = ['name'=>  $ user_details-> name,'new_pass'=>  $ new_pass]; 
 
 Mail :: send('email@newpassword',$ mail_data,function($ message)
 {
 $ message-> from('us@example.com','Laravel'  ); 
 
 $ message-> to($ email); 
 
}); 
 
返回response() - > json(['status'=>'无效']);  
} 
 
} 
 
} 
  code>  pre> 
 
 

如果我使用 $ message->来实际邮件正常工作('sometest @ testmail.com'); code>而不是 $ message->到($ email); code>。 以下是我得到的错误。
p>

感到奇怪为什么 $ email code>导致错误 。 p> div>

You have to pass the $email to the anonymous function

Mail::send('emails.newpassword', $mail_data, function($message) use ($email) {
...
});