Laravel Password remind - connection refused 61 - php

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, i.e. 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'
));

Maybe it is trying to send an e-mail and it is not working.

Related

SwiftMailer Connection could not be established with host

I am getting an unexpected problem with emails being sent from my site. It had been working fine for some time and all of a sudden seems to have stopped for no apparent reason.
[Swift_TransportException] exception 'Swift_TransportException' with message 'Connection could not be established with host [Connection timed out #110]' in vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:265
In my web.php
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'mail.website.com',
'username' => 'username',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
What could have happened for this to stop working and how should I be fixing it?
I am using google apps for my emails, but I have always used this config where I connect to my mail server. I'm not sure why it suddenly stopped working.
Same thing thing happened to me in yii , couple of days ago.Solved it by changing the port.
Try,
'port' => 26,
it's looking for the server mail.website.com but isn't able to resolve it.
use this domain smtp.gmail.com and port 25 or 465.
if (!$this->_stream = fsockopen($host, $this->_params['port'], $errno, $errstr, $timeout))
{
throw new Swift_TransportException(
'Connection could not be established with host ' . $this->_params['host'] .
' [' . $errstr . ' #' . $errno . ']'
);
}
So you either need to input a valid smtp server or wrap the send() line in a try/catch to catch the exception and either log it somewhere or ignore it.
Please checkif the port you use is really the port used by your mail server.

Failed to send an email in laravel 5

My code is like this :
public function sendMail(array $data)
{
$data = explode('#', $data['id']);
$email_from = Auth::user()->email;
$email_to = $data[4];
$subject = 'Send Email Test';
$data_user = ['user_name' => $data[1], 'full_name' => $data[2].' '.$data[3] ];
$sent = Mail::send('backend.auth.success_approved', $data_user, function ($mail) use ($email_to, $email_from, $subject)
{
$mail->from($email_from)
->to($email_to)
->subject($subject);
});
}
My configuration in mail.php :
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'ssl://secure.emailsrvr.com'),
'port' => env('MAIL_PORT', 465),
'from' => ['address' => 'myemail#chel.com', 'name' => 'myname'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME', 'myemail#chel.com'),
'password' => env('MAIL_PASSWORD', 'mypassword'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
There is error message :
Swift_TransportException in StreamBuffer.php line 265: Connection could not be established with host ssl://secure.emailsrvr.com [php_network_getaddresses: getaddrinfo failed: The requested name is valid, but no data of the requested type was found. #0].
How to solve this problem?
Thank you.
From the error message I believe that for some reason the domain (secure.emailsrvr.com) of the mail server cannot be resolved.
If you are on a shared hosting you should ask your hosting provider, if you are on a dedicated server or vps you should ping the hostname and see if it can be resolved.
I've done the following things, it worked for me.
Create an email account on the server. Now we have MAIL_USERNAME and MAIL_PASSWORD.
Make the following changes to create global variables in .env file of Laravel framework.
MAIL_DRIVER=smtp
MAIL_HOST=yourhost
MAIL_PORT=465
MAIL_ENCRYPTION=ssl
MAIL_USERNAME=youremail#something.com
MAIL_PASSWORD=yourpassword
Or else you can add the above changes in your config/mail.php. It'll work.
some email parameters in laravel 5+, are defined in .env file, sometimes laravel dont recognize other parameters outside .env file,
check first if your parameters are sent, if not try to send an email to your personal account and try to change the parameters in the .env file

Silex + Swift Mailer not working

I have a Silex app with Swift Mailer, but it seems like the configuration was not loaded from $app['swiftmailer.options'].
I registered the service in my bootstrap file
$app->register(new SwiftmailerServiceProvider());
And in my configuration file
$app['swiftmailer.options'] = array(
'host' => 'smtp.mandrillapp.com',
'port' => '587',
'username' => 'MY_USERNAME',
'password' => 'MY_PASSWORD',
'encryption' => null,
'auth_mode' => null
);
And then I send my email with
$message = \Swift_Message::newInstance()
->setSubject($this->app['forum_name'] . ' Account Verification')
->setFrom(array('no-reply#domain.com'))
->setTo(array('recipient#example.com'))
->setBody('My email content')
->setContentType("text/html");
$this->app['mailer']->send($message);
The send function returns 1 but the email was never sent. But, when I try manually creating an instance of Swift_SmtpTransport, the email would send.
$transport = \Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587)
->setUsername('MY_USERNAME')
->setPassword('MY_PASSWORD');
...
$mailer = \Swift_Mailer::newInstance($transport);
$mailer->send($message);
So the problem is the $app['swiftmailer.options'] is not read or loaded. Am I missing something here?
I'm following the instructions from here.
By default the SwiftmailerServiceProvider uses a spooled transport to queue up emails and sends them all during the TERMINATE stage (after a response is sent back to the client). If you don't call Application->run(), you are bypassing this process. Your mail will stay in the spool and never get sent.
If you want to sent mail outside of the normal Silex flow, you can flush the spool manually with
if ($app['mailer.initialized']) {
$app['swiftmailer.spooltransport']
->getSpool()
->flushQueue($app['swiftmailer.transport']);
}
That's taken directly from the SwiftmailerServiceProvider.
Or you can simply turn off spooling with
$app['swiftmailer.use_spool'] = false;
Try this:
$app->register(new \Silex\Provider\SwiftmailerServiceProvider(), array(
'swiftmailer.options' => array(
'sender' => 'sender',
'host' => 'host',
'port' => 'port',
'username' => 'username',
'password' => 'password'
)
));
It is not in the documentation.

Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host [Operation timed out #60]

I'm using Silex SwiftmailerServiceProvider.
Now i need to send an email from my website but i keep getting this error.
I searched all over the place but i find only the #110 errors etc.
The code i'm using at the moment:
$message = \Swift_Message::newInstance()
->setSubject('[OFFERTE]' . $data['name'])
->setFrom(array('fromemail'))
->setTo(array('myemail'))
->setBody($data['comment'],'text/html');
$app['mailer']->send($message);
This code above is the code inside my page.php (landing page).
$app->register(new Silex\Provider\SwiftmailerServiceProvider(), array(
'swiftmailer.options' => array(
'host' => 'host',
'port' => 'port',
'username' => 'username',
'password' => 'password',
'encryption' => null,
'auth_mode' => null
)
));
The code above here is what's in my bootstrap.php (if you're familiar with silex).
Anyone an idea what might be the source of this error?
Thanks!
Pieter-Jan
EDIT: i did fill in the host etc in boostrap.php
For all others who are having the same issue i had...
If you're getting this message you are doing something wrong. The problem i was having is that some data was wrong to make the connection. So triple check the data you need.

Internal server error using Swiftmailer on Silex

I'm working on a Silex project and I'm trying to send an email using the Swiftmailer provider but always get an internal server error(500).
Registering:
$app->register(new Silex\Provider\SwiftmailerServiceProvider(), array(
'swiftmailer.options' => array(
'host' => 'smtp.gmail.com',
'port' => '465',
'username' => 'my_email',
'password' => 'my_password')
));
If I call the mailer $app['mailer'] throw an internal server error.
If I try with the documentation example I got an internal server error:
$app->post('/feedback', function () use ($app) {
$request = $app['request'];
$message = \Swift_Message::newInstance()
->setSubject('[YourSite] Feedback')
->setFrom(array('noreply#yoursite.com'))
->setTo(array('feedback#yoursite.com'))
->setBody($request->get('message'));
$app['mailer']->send($message);
return new Response('Thank you for your feedback!', 201);
});
I don't know what's the problem, I have no troubles with the other providers.
Any ideas?
Would it help to add the following entries in your 'swiftmailer.options' array? Gmail by default uses ssl on port 465.
'encryption' => 'ssl',
'auth_mode' => 'login',
[Update]
If you define namespace in your code, need to add '\' in front of Silex\Provider..
$this->register(new Silex\Provider\SwiftmailerServiceProvider(), array(
to
$this->register(new \Silex\Provider\SwiftmailerServiceProvider(), array(

Categories