简体   繁体   中英

Laravel Password remind - connection refused 61

I am stumped.

I am using Laravel's Password::remind, which has already been written for me, so there is nothing that I have changed:

try {

        $reset = Password::remind($credentials);

    } catch (Exception $e) {

        throw new Exception($e->getMessage());
    }

When I submit the form, then I receive the following exception:

Exception

Connection could not be established with host localhost [Connection refused #61] 

Which points to my throw exception line above

In my app/config/mail.php file, I have tried everything from mail to sendmail, from localhost to smtp.gmail.com - whatever I change in this config file, Laravel still thinks that it is localhost. Even tried "/usr/sbin/sendmail -t -i"

I have restarted apache and fpm - the error does not change.

When I try mail(email, title, message) - it works just fine. Of course, my goal is to not just send an email but to use Laravel's Password::remind - function where it sends an email with a link for the user to reset their password.

I have changed the /usr/local/etc/php/5.5/php.ini file, both the smtp and smtp_port

What do I need to do, this seems so straight forward in their documentation and no one else has complained about this issue for connection refused # 61. There are other connection refused and they have nothing to do with the built in Password::remind. This is driving me nuts.

I am running fpm-nginx.

Thanks in advance

Just to be on the safe side in respect to any configuration issues, I suggest you to try your application in a closed environment such as Homestead. This way, ie by relying on a fresh virtual machine, you might be able to figure out whether it is a configuration issue on the level of the different applications (apache, php, etc.) you are using. Otherwise, you would have to reinspect your code again. You can find more information on Homestead here: http://laravel.com/docs/4.2/homestead

OK, there were a couple of configurations that had to be in place and I am posting this answer in case anyone else using Yosemite is having this issue.

First, from my searching for the error "Connection refused #61" this is usually related to connectivity with a database as Korush suggested above. However, if I typed in an email that was not part of the database, Laravel would come back with a message that such and such email was not found, which told me that it was connected to the database, from the stand point of searching the email that was entered.

However, if a person does not have a "password_reminders" table in their localhost database, then a person would receive a connection refused error - be sure that you have this for Laravel to use in your localhost db:

CREATE TABLE password_reminders (
 email VARCHAR(50) NOT NULL,
 token VARCHAR(100) NOT NULL,
 created_at TIMESTAMP
)

Second, Laravel can use the mail server on your system. In my case, I am using Yosemite, which has "postfix" available in the terminal:

sudo postfix start

Here is my local config which allows Laravel to use the "password_reminders" table, which is located in app/config/database.php:

    'local' => array(
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'database'  => 'yourdb',
        'username'  => 'yourusername',
        'password'  => 'yourpassword',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ), 

Within the app/config/mail.php:

'driver' => 'smtp',
'host' => 'localhost',
'port' => 25,
'from' => array('address' => 'service@yourdomain.com', 'name' => 'Your Company'),
'encryption' => '',
'username' => null,
'password' => null,
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,

I still need to figure out how to get the redirects and messages to display, but this is working for the emailing a link to reset the password:

public function request()
{
    $message = "";
    $session = null;

    $request = array('email' => Input::get('USER_EMAIL'));

    Password::remind(Input::only('USER_EMAIL'), function($message)
    {
        $message->subject('Password Reminder');
    });

    if ($request == 'reminders.sent') {

        $session = 'message';
        $success = true;
        $message = 'Email with further instruction has been sent to "' . Input::get('USER_EMAIL'). '".';
        return Password::remind($request);
    } elseif ($request == 'reminders.user') {

        $session = 'error';
        $success = false;
        $message = 'Email Address: ' . Input::get('USER_EMAIL') . ' WAS NOT FOUND!';
        return Password::remind($request);
    }else{
        $message = 'Not meeting either condition "' . Input::get('USER_EMAIL') . '".';
        return Password::remind($request);
    }

    Session::flash($session, $message);
    return Redirect::to('/').with($session, $message);

}

Here are my routes related to password remind:

Route::get('password/reset', array(
 'uses' => 'PasswordController@remind',
 'as' => 'password.remind'
));

Route::post('password/reset', array(
 'uses' => 'PasswordController@request',
 'as'   => 'password.request'
));

Route::get('password/reset/{token}', array(
 'uses' => 'PasswordController@reset',
 'as' => 'password.reset'
));

Route::post('password/reset/{token}', array(
 'uses' => 'PasswordController@update',
 'as' => 'password.update'
));

也许它正在尝试发送电子邮件,但无法正常工作。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM