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

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?

Mar 31 in Laravel by kartik
• 11,290 points
790 views

1 answer to this question.

0 votes

Hii @kartik,

if you are using Swift Mailer: please ensure that your $transport variable is similar to the below, based on tests i have done, that error results from ssl and port misconfiguration. note: you must include 'ssl' or 'tls' in the transport variable.

EXAMPLE CODE:

// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'))
  ->setUsername(you@example.com)
  ->setPassword(password)
;

// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);

// Create a message
$message = (new Swift_Message('News Letter Subscription'))
  ->setFrom(['app@example.com' => 'A Name'])
  ->setTo(['someone@example.com' => 'A Name'])
  ->setBody('your message body')
  ;

// Send the message
$result = $mailer->send($message);
answered Mar 31 by Niroj
• 22,790 points

Related Questions In Laravel

0 votes
1 answer

How to pass CSRF token with ajax request in Laravel?

Hey, In between head, tag put <meta name="csrf-token" ...READ MORE

answered Mar 24 in Laravel by Dey
109 views
0 votes
1 answer

How to pass URL param in Laravel?

Hello, First you have to go to routes ...READ MORE

answered Mar 18 in Laravel by Niroj
• 22,790 points
108 views
0 votes
1 answer

How to pass data through URL and access through controller in Laravel?

Hello, You can  first refer how to  Create controller through ...READ MORE

answered Mar 18 in Laravel by Niroj
• 22,790 points
224 views
0 votes
1 answer

How to identify wheather the request is HTTP GET or HTTP POST in Laravel?

Hey, In order to identify the type of ...READ MORE

answered Mar 19 in Laravel by Niroj
• 22,790 points
40 views
0 votes
1 answer

How to make anchor tag with routing using Laravel?

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

answered Mar 18 in Laravel by Niroj
• 22,790 points
434 views
0 votes
1 answer

What is redirection in Laravel?

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

answered Mar 18 in Laravel by Niroj
• 22,790 points
62 views
0 votes
1 answer

How to install Laravel via composer?

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

answered Mar 23 in Laravel by Niroj
• 22,790 points
64 views
0 votes
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 in Laravel by Niroj
• 22,790 points
151 views
0 votes
1 answer

Error:login in Laravel. How to solve?

Hey, First check if your model login has a field password in ...READ MORE

answered Mar 26 in Laravel by Niroj
• 22,790 points
86 views
0 votes
1 answer

How to make a new page with routing using Laravel?

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

answered Mar 18 in Laravel by Niroj
• 22,790 points
72 views