0

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
MAIL_USERNAME=mygmail@gmail.com
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' => 'sender@gmail.com', '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('receiver@yahoo.com','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

Yoksan Herlie
  • 123
  • 3
  • 11
  • Possible duplicate of [Using gmail smtp via Laravel: Connection could not be established with host smtp.gmail.com \[Connection timed out #110\]](http://stackoverflow.com/questions/25572907/using-gmail-smtp-via-laravel-connection-could-not-be-established-with-host-smtp) – prateekkathal Sep 10 '16 at 05:59

2 Answers2

0

Did you try by changing these

MAIL_PORT=465
MAIL_ENCRYPTION=ssl
Parithiban
  • 1,656
  • 11
  • 16
0

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)

Paul Basenko
  • 895
  • 1
  • 9
  • 22