Search code examples
phpemaillaravelurlforgot-password

Laravel 5.1 - Built in password reset functionality not sending email with token


OVERVIEW:

I'm creating a password reset functionality using the built in system in Laravel 5.1, I have followed the instructions exactly how it says here.

The view in resources/views/emails/password.blade.php receives a variable $token which contains the password reset token to match the user to the password reset request. Within the view, I have the following code which is supposed to create a URL link of the page where the user set the new password:

   Click here to reset your password: {{ url('password/reset/'.$token) }}

PROBLEM:

It does not send the email at all. But I have realized that, if I remove the last trailing slash (see below):

   Click here to reset your password: {{ url('password/reset'.$token) }}

I receive something like http://mywebsite.com/password/reset35df435dfgdfg...

CONCLUSION:

Whenever there is a trailing slash between password/reset/ and the $token, the email is not sent. Even when I manually type the URL.

Why would the / before the $token affect on the email being sent? Any ideas?

ATTEMPTED SOLUTIONS:

 url('password/reset', [$token]); //DID NOT WORK

 action('Auth\PasswordController@getEmail', ['token' => $token]);  //DID NOT WORK

 route('password/email', ['token' => $token]); //DID NOT WORK

 url('password/reset/'.$token); //DID NOT WORK

Solution

  • I found a solution! This is not usual, but if you add a backward trailing slash, it will keep the forward slash and it won't have a problem with the token.

    url('password/reset\/', [$token]);

    Thanks & Good luck!