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.
Feeling strange why $email
causing error.