5

I am using mailgun with laravel 5.6 to send email but its return error( Expected response code 220 but got an empty response). The following is my all file settings.

.env FILE

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME = postmaster@domainname 
MAIL_PASSWORD = password
MAILGUN_DOMAIN = domainname 
MAILGUN_SECRET = key
MAIL_ENCRYPTION=tls

mail.php File

<?php

return [

     'mailgun' => [
        'domain' => env('MAILGUN_DOMAIN'),
        'secret' => env('MAILGUN_SECRET'),
    ],
    'ses' => [
        'key' => env('SES_KEY'),
        'secret' => env('SES_SECRET'),
        'region' => 'us-east-1',
    ],
    'sparkpost' => [
        'secret' => env('SPARKPOST_SECRET'),
    ],
    'stripe' => [
        'model' => App\User::class,
        'key' => env('STRIPE_KEY'),
        'secret' => env('STRIPE_SECRET'),
    ],
];

services.php File

<?php

return [
    'driver' => env('MAIL_DRIVER', 'mailgun'),
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => 'aakanskhi.cuminte@gmail.com', 'name' => 'Aakankshi Gupta'],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('postmaster@domain'),
    'password' => env('mailgun password'),
    'sendmail' => '/usr/sbin/sendmail -bs',
    'markdown' => [
        'theme' => 'default',
        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],
];
    public function testmail(){
       $user = User::findOrFail(8);
       Mail::send('emails.test',  ['user' => $user], function ($message) {
       $message->from('us@example.com', 'Laravel');
       $message->to('aakankshi.cuminte@gmail.com')->subject('Your Reminder!');
     });
    }

When I run the code it gives me following error message:

Swift_TransportException Expected response code 220 but got an empty response

How do I resolve this error message?

Community
  • 1
  • 1
Aakankshi Gupta
  • 305
  • 1
  • 6
  • 18

2 Answers2

2

Just run this code on the terminal:

php artisan config:cache
Pingolin
  • 3,161
  • 6
  • 25
  • 40
0

For Mailgun only you have to specify the following fields in .env file, that's it.

MAIL_DRIVER=mailgun

MAILGUN_DOMAIN=XY.mailgun.org

MAILGUN_SECRET=key-XYZ

Community
  • 1
  • 1
dipenparmar12
  • 3,042
  • 1
  • 29
  • 39