I'm debugging a Laravel 6 application which isn't sending password reset emails to the users. All other emails send by the application work fine and I've tried a different mailserver without success. The applications doesn't throw any errors in the logs and returns that the reset email was send successfully, if a valid email address was entered.
The reset emails should be send by the default ForgotPasswordController
. Only the methods sendResetLinkResponse
and sendResetLinkFailedResponse
were modified to some custom JSON response.
class ForgotPasswordController extends Controller
{
use SendsPasswordResetEmails;
protected function sendResetLinkResponse(Request $request, $response)
{
return response()->json([...], 200);
}
protected function sendResetLinkFailedResponse(Request $request, $response)
{
return response()->json([...], 422);
}
}
The endpoint calls the sendResetLinkEmail
function, definied in the SendsPasswortResetEmails
trait.
/**
* Send a reset link to the given user.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
*/
public function sendResetLinkEmail(Request $request)
{
$this->validateEmail($request);
// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
$response = $this->broker()->sendResetLink(
$this->credentials($request)
);
return $response == Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($request, $response)
: $this->sendResetLinkFailedResponse($request, $response);
}
This functions behaves like expected, with a valid email address the overwritten sendResetLinkResponse
method is called. Also entries in the database table password_resets
are generated.
The User
model has the CanResetPasswordContract
and the CanResetPassword
trait, like described in the documentation: https://laravel.com/docs/6.x/passwords. Also the email column on the User
model and in the database is called just email
.
I've read in another post that MAIL_FROM
attributes in the .env
could cause some problems, but I think that`s not the problem in my case also because all other emails that are send by the application work fine.
MAIL_FROM_ADDRESS=email@test.com
MAIL_FROM_NAME="My Application"
I hope you can point me in the right direction to track down the issue. Thank you!
source https://stackoverflow.com/questions/77282606/laravel-6-forgotpasswortcontroller-doesnt-send-reset-emails
No comments:
Post a Comment