简体   繁体   中英

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' => 'mymail@gmail.com', 'name' => 'Auth'),
    'encryption' => 'ssl',
    'username' => 'mymail@gmail.com',
    // '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('mail@gmail.com', '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]

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

在mail.php中更改'port'=> 587

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.

在此处输入图片说明

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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