简体   繁体   English

Laravel密码提醒-连接被拒绝61

[英]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: 我正在使用Laravel的Password :: remind,它已经为我编写了,所以我没有什么改变:

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. 在我的app / config / mail.php文件中,我尝试了从邮件到sendmail,从本地主机到smtp.gmail.com的所有操作-无论在此配置文件中进行什么更改,Laravel仍认为它是本地主机。 Even tried "/usr/sbin/sendmail -t -i" 甚至尝试过“ / usr / sbin / sendmail -t -i”

I have restarted apache and fpm - the error does not change. 我已经重新启动了apache和fpm-错误不会改变。

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. 当然,我的目标不仅是发送电子邮件,还使用Laravel的Password :: remind-该功能通过向用户发送带有链接的电子邮件来重置用户密码。

I have changed the /usr/local/etc/php/5.5/php.ini file, both the smtp and smtp_port 我已经更改了/usr/local/etc/php/5.5/php.ini文件,即smtp和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. 我需要做的是,在他们的文档中这似乎很简单,没有其他人抱怨这个问题,因为连接被拒绝#61。还有其他连接被拒绝,它们与内置的Password :: remind无关。 This is driving me nuts. 这让我发疯。

I am running fpm-nginx. 我正在运行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. 为了安全起见,建议您在封闭的环境(如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. 通过这种方式,即依靠新的虚拟机,您可能能够确定所使用的不同应用程序(apache,php等)级别上的配置问题。 Otherwise, you would have to reinspect your code again. 否则,您将不得不再次检查代码。 You can find more information on Homestead here: http://laravel.com/docs/4.2/homestead 您可以在此处找到有关Homestead的更多信息: 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. 首先,从我搜索错误“连接被拒绝#61”开始,这通常与Korush上面建议的与数据库的连接有关。 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. 但是,如果我输入的电子邮件不是数据库的一部分,那么从搜索数据库的角度来看,Laravel会返回一条消息,提示未找到这样的电子邮件,并告诉我该电子邮件已连接到数据库。输入的电子邮件。

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: 但是,如果某人在其本地主机数据库中没有“ password_reminders”表,则该人将收到连接被拒绝的错误-请确保您具有供Laravel在本地localhost数据库中使用的错误:

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. 其次,Laravel可以在您的系统上使用邮件服务器。 In my case, I am using Yosemite, which has "postfix" available in the terminal: 就我而言,我使用的是优胜美地(Yosemite),其在终端中具有“后缀”:

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: 这是我的本地配置,允许Laravel使用“ password_reminders”表,该表位于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: 在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'
));

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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