Swift_TransportException in AbstractSmtpTransport.

2019-08-04 21:33发布

问题:

I'm trying to create a contact form using laravel 5.4 and I added my server email details to the .env and the mail.php but I'm getting this error

Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "421", with message "421 Unexpected failure, please try later "

If I try this and I use mailtrap it works fine.

This is my mail.php

return [

    'driver' => env('MAIL_DRIVER', 'smtp'),

    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

    'port' => env('MAIL_PORT', 587),

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'info@website.co.za'),
        'name' => env('MAIL_FROM_NAME', 'Info'),
    ],

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    'username' => env('MAIL_USERNAME'),

    'password' => env('MAIL_PASSWORD'),

    'sendmail' => '/usr/sbin/sendmail -bs',

    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

My .env file

MAIL_DRIVER=smtp
MAIL_HOST=hosting.com
MAIL_PORT=587
MAIL_USERNAME=info@website.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=

回答1:

Check the config/mail.php

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', ''),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => null, 'name' => null],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME', ''),
    'password' => env('MAIL_PASSWORD', ''),
    'sendmail' => '/usr/sbin/sendmail -bs',
];

Make sure the .env file has the following

MAIL_DRIVER=smtp
MAIL_HOST=hosting website 
MAIL_PORT=587
MAIL_USERNAME=your username
MAIL_PASSWORD=your password
MAIL_ENCRYPTION=tls

Also clear the config cache

php artisan config:cache