Error Swift TransportException Expected response code 220 but got code with message

0 votes

I am using Laravel Mail function to send email. The following is my 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 I run the code it gives me following error message:

Swift_TransportException

Expected response code 220 but got code "", with message ""

I have created a SendMail.php file in view which contains some data.

How do I resolve this error message?

Jul 30, 2020 in Laravel by kartik
• 37,520 points
4,363 views

1 answer to this question.

0 votes

Hello @kartik,

This problem can generally occur when you do not enable two step verification for the gmail account (which can be done here) you are using to send an email. So first, enable two step verification, you can find plenty of resources for enabling two step verification. After you enable it, then you have to create an app password. And use the app password in your .env file. When you are done with it, your .env file will look something 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 your 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 and php artisan config:clear, then check, email should work.

Hope it helps!!
Thank you!

answered Jul 30, 2020 by Niroj
• 82,840 points

Related Questions In Laravel

0 votes
1 answer

Error:return \Redirect::route('regions')->with('message', 'State saved correctly!!!');

Hello @kartik, You can pass the route parameters ...READ MORE

answered Dec 1, 2020 in Laravel by Niroj
• 82,840 points
1,017 views
0 votes
1 answer

How can I get the error message for the mail() function?

Hello @kartik, You can use error_get_last() when mai l()returns false. $success = mail('example@example.com', ...READ MORE

answered Jul 30, 2020 in Laravel by Niroj
• 82,840 points
9,584 views
0 votes
1 answer

Error:Loading composer repositories with package information Updating dependencies (including require-dev) Killed

Hello @kartik, The "Killed" message usually means your ...READ MORE

answered Aug 4, 2020 in Laravel by Niroj
• 82,840 points
8,122 views
0 votes
1 answer

Error:Laravel Migration table already exists but i want to add new not the older

Hello @kartik, You need to run php artisan migrate:rollback if ...READ MORE

answered Aug 11, 2020 in Laravel by Niroj
• 82,840 points
11,560 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,011 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
2,992 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,916 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,678 views
0 votes
2 answers

How to solve expected response code 220 but got code “”, with message “” in Laravel?

This problem can generally occur when you ...READ MORE

answered Dec 16, 2020 in Laravel by Gitika
• 65,770 points
42,380 views
0 votes
1 answer

Error: 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue?

Hii, I had same problem when responding on ...READ MORE

answered Mar 30, 2020 in Laravel by Niroj
• 82,840 points
53,437 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP