Mohammed Zayan
Mohammed Zayan

Reputation: 899

Laravel 4.2 and smtp.gmail.com

I have a problem with sending an email with google SMTP using laravel 4.2

This is the mail.php file

return array(
    'driver' => 'smtp',
    'host' => 'smtp.gmail.com',
    'port' => 465,
    'from' => array('address' => '[email protected]', 'name' => 'Auth'),
    'encryption' => 'ssl',
    'username' => '[email protected]',
    // 'username' => 'mymail',
    'password' => 'mypass',
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false
);

and this is the controller code

class HomeController extends BaseController {
     public function home(){
          Mail::send('emails.auth.test', array('name' => 'Auth'), function($message){
                $message->to('[email protected]', 'Name Name')->subject('Test Email');
          });
          return View::make('home');
     }
}

and this is the view file

Hello {{ $name }}!

in php.ini file

extension=php_openssl.dll

and I have enabled Access for less secure apps from https://www.google.com/settings/security/lesssecureapps

After that, I have this error Connection could not be established with host smtp.gmail.com [ #0]

Upvotes: 2

Views: 1274

Answers (3)

Othman Mahmoud
Othman Mahmoud

Reputation: 153

you need to make some changes in your Gmail settings. Login to your Google account and click on My Account. Once you are on My Account page then click on Sign-in & Security.

enter image description here

enter image description here

Upvotes: 1

Abhinav Saraswat
Abhinav Saraswat

Reputation: 819

change 'port' => 587, in mail.php

Upvotes: 0

Murugan Vellaisamy
Murugan Vellaisamy

Reputation: 344

Pls change this in your mail.php

1) from 'encryption' => 'ssl' to 'encryption' => 'tls'

2) from 'driver' => 'smtp', to 'driver' => 'sendmail'

its work for me... All the best

Upvotes: 2

Related Questions