php - Expected response code 220 but got code "", with message "" in Laravel -


i using laravel mail function send email. following app/config/mail.php file settings.

'driver' => 'sendmail', 'host' => 'smtp.gmail.com', 'port' => 587, 'from' => array('address' => 'email@gmail.com', 'name' => 'myname'), 'encryption' => 'tls', 'username' => 'myusername', 'password' => "password", 'sendmail' => '/usr/sbin/sendmail -bs', 'pretend' => false, 

controller mail method

//send mail      mail::send('sendmail', array('key' => 'value'), function($message) {     $message->to('emailid@hotmail.com', 'sender name')->subject('welcome!'); }); 

when run code gives me following error message:

swift_transportexception

expected response code 220 got code "", message ""

i have created sendmail.php file in view contains data.

how resolve error message?

this problem can occur when not enable 2 step verification gmail account using send email. first, enable two step verification, can find plenty of resources enabling 2 step verification. after enable it, have create app password. , use app password in .env file. when done it, .env file like.

mail_driver=smtp mail_host=smtp.gmail.com mail_port=587 mail_username=<<your email address>> mail_password=<<app password>> mail_encryption=tls 

and mail.php

<?php  return [     'driver' => env('mail_driver', 'smtp'),     'host' => env('mail_host', 'smtp.gmail.com'),     'port' => env('mail_port', 587),     'from' => ['address' => '<<your email>>', 'name' => '<<any name>>'],     'encryption' => env('mail_encryption', 'tls'),     'username' => env('mail_username'),     'password' => env('mail_password'),     'sendmail' => '/usr/sbin/sendmail -bs',     'pretend' => false,  ]; 

after doing so, run php artisan config:cache , php artisan config:clear, check, email should work.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -