3
votes

I am trying to implement a password reset on my Laravel 5.1 app. I have followed the docs (http://laravel.com/docs/5.1/authentication#resetting-passwords) to get this working. However whenever I click on my 'reset password' button on my /password/email/ no email is ever sent.

I have intentionally entered incorrect emails and I am getting the appropriate error however when I enter a correct email no email is sent and I get no type of message or any emails.

I have looked at my database and it does looks as though a password reset token being created, just no email is sent.

My email configuration is working properly as other parts of my application sends email properly, only this one section is not sending the emails. Any help will be appreciated as I do not what else to check.

Michael

routes.php: `

// Password reset link request routes...
Route::get('password/email', ['as' => 'password/email', 'uses' => 'Auth\PasswordController@getEmail']);
Route::post('password/email', 'Auth\PasswordController@postEmail');

    // Password reset routes...
    Route::get('password/reset/{token}', 'Auth\PasswordController@getReset');
    Route::post('password/reset', 'Auth\PasswordController@postReset');

password.blade.php:

<form id="contact-form" class="contact-section" method="POST" action="/password/email">
            <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
            <span class="pre-input"><i class="fa fa-envelope-o"></i></span>
            <input class="name plain buffer" type="email" name="email" placeholder="Email" value="{{ old('email') }}">
            <input id="send" class="plain button yellow" type="submit" value="Reset Password">
              @foreach($errors->all() as $error)
              <font size="3" color="red">{{ $error }}</font>
              @endforeach

          </form> 

resources/views/emails/password.blade.php:

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

Update I have added a Log to the postEmail function.

    public function postEmail(Request $request)
{
    $this->validate($request, ['email' => 'required|email']);

    $response = Password::sendResetLink($request->only('email'), function (Message $message) {
        $message->subject($this->getEmailSubject());
 Log::info('Password Reset Execute -1 '); //Does work here


    });

    switch ($response) {

        case Password::RESET_LINK_SENT:
            return redirect()->back()->with('status', trans($response));

        case Password::INVALID_USER:
            return redirect()->back()->withErrors(['email' => trans($response)]);
    }

    Log::info('Password Reset Execute - 2'); //Will not work here
}
2
Please also post the contents of your email view. You should have one in resources/views/emails/password.blade.phpmaiorano84
@maiorano84 I just added that file, however all I did on that was copied and paste the code directly from Laravel site.Michael
Was the file not there before? Because the existence of that file is required by Auth in order to email anything. Additionally, are you doing this in Homestead or some kind of local VM? Or is this on a public server? Lastly what are your mail settings under config/mail.php and your .env file?maiorano84
@maiorano84 Yes I already had the email view created and in the right location, although I had attempted a run before and of course it threw an error that that view could not be found. I currently have this hosted on a public VM with DigitalOcean. And I have my mail config under config/mail.php with the code: 'driver' => env('MAIL_DRIVER', 'mandrill'), Michael
Do you receive any errors, or just the email is not sent. Would you check the laravel.log?Mina Abadir

2 Answers

3
votes

If the issue is invalid sender, make sure you pass the correct sender

$message->from('[email protected]', 'Your Application');
8
votes

I added those in .env and password reseting is working again

[email protected]
MAIL_FROM_NAME=xxxx