Search code examples
phplaravelemailsmtpsendgrid

smtp.sendgrid.net connection refused to connect on web server.... correctly working in localhost


I am using sendgrid to send mail in my laravel application . I successfully tested application on localhost its working fine with mail facility also. but as i deployed to web server its started showing error " Swift_TransportException Connection could not be established with host smtp.sendgrid.net [Connection refused #111] ". Thanks in advance. Image Showing Error php artisan config:clear ,cache:clear and config:cache i tried all .... but nothing works.

.env file

MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=USERNAME
MAIL_PASSWORD=PASSWORD
MAIL_ENCRYPTION=tls

config/mail.php

'host' => env('MAIL_HOST', 'smtp.sendgrid.net'),
'port' => env('MAIL_PORT', 587),
'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'email@email.com'),
        'name' => env('MAIL_FROM_NAME', 'From Name'),
    ],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME','USERNAME'),
'password' => env('MAIL_PASSWORD','PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
        'theme' => 'default',

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

        'stream' => [
       'ssl' => [
          'allow_self_signed' => true,
          'verify_peer' => false,
          'verify_peer_name' => false,
       ],
    ],

Solution

  • I used ichikawa/laravel-sendgrid-driver for sending mails using sendgrid and its working fine for me. get it on GITHUB