I'm using mail function to override reset password auth.
public function resetPassword(Request $request){
$new_password = rand(120400, 940490);
$email=$request->input("email");
$user = new User();
$count = $user -> where('email',$email) -> count();
if ($count == 0){
$meta = $api_meta->metaData(false,"Email does not exist.",[],'');
return ['meta'=>$meta];
}
$user = $user -> where('email',$email) -> get() -> first();
$user -> password = bcrypt($new_password);
$user -> save();
$to = $email;
$subject = 'user message';
$message = "
Your new password is : $new_password
";
$headers = 'From: ' .$email. "\r\n";
mail($to, $subject, $message, $headers);
}
In Router.php I modified from :
$this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
to:
$this->post('password/email', 'UserController@resetPassword')->name('password.email');
I think everything there is alright but I get an error :
Cannot send message without a sender address
Make sure you've defined from
in the config/mail.php
:
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
If you didn't edit it, add sender email and name to the .env
:
MAIL_FROM_ADDRESS=me@example.com
MAIL_FROM_NAME=MyName
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.