0
votes

I'm learning Laravel 5.1 mail for my project. So, I try to send simple email first from a new Laravel 5.1 application on my localhost.

this is my .env config file

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mygmailpassword
MAIL_ENCRYPTION=tls

and this is my config/mail.php

'driver' => env('MAIL_DRIVER', 'smtp'),

'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

'port' => env('MAIL_PORT', 587),

'from' => ['address' => '[email protected]', 'name' => 'Sender'],

'encryption' => env('MAIL_ENCRYPTION', 'tls'),

'username' => env('MAIL_USERNAME'),

'password' => env('MAIL_PASSWORD'),

'sendmail' => '/usr/sbin/sendmail -bs',

this is my function to send the email

Mail::send('emails.email', ['user'=>'Sender'], function($m){

    $m->to('[email protected]','receiver')->subject('subject');
});

With this, when I run the application, it always return the error

Swift_TransportException in StreamBuffer.php line 265:

Connection could not be established with host smtp.gmail.com [Connection timed out #110]

What I've tried:

  • Turn on 'less secure apps' on google account
  • 2-step verification (generate an app password) and use it on (MAIL_PASSWORD on .env config)

But, none of this succeed. What am I doing wrong here?

PS: My OS is Linux Ubuntu 14.04

2

2 Answers

0
votes

Did you try by changing these

MAIL_PORT=465
MAIL_ENCRYPTION=ssl
0
votes

Write a ticket to your hosting support. I've had the same problem: my mails were successfully sent at localhost, but at the hosting there were troubles.

I've wrote to the technical support and the engineer said that the port 587 is blocked by default and they can unblock it if I wish. When the port was unblocked the error disappeared.

So easy)