1

I am working on a Laravel project and try to send emails using mailjet. Sending mails local works fine, but using the same settings on my centos 7 webserver gives me an error which I can't resolve for days now.

.env settings

MAIL_MAILER=smtp
MAIL_DRIVER=smtp
MAIL_HOST=in-v3.mailjet.com
MAIL_PORT=587
MAIL_USERNAME=***
MAIL_PASSWORD=***
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=no-reply@***.com
MAIL_FROM_NAME="${APP_NAME}"

Sending the email

Mail::send('emails.auth.verify-email', ['token' => $token, 'user' => $user], function($message) use($user){
   $message->to($user->email);
   $message->subject('Email Verification Mail');
});

Error on CentOS 7 Server

Swift_TransportException
Connection could not be established with host in-v3.mailjet.com :stream_socket_client(): unable to connect to tcp://in-v3.mailjet.com:587 (Permission denied)

I already tried

  • restarting apache
  • sudo reboot
  • php artisan cache:clear
  • php artisan config:clear
  • I have also tried mailgun instead of mailjet, got me the same error (only on the server, worked fine local)
  • hard coding the connection credentials in config/mail.php instead of loading them from the .env file

as requested in the comments, here is the output of: dd(Config::get('mail'))

array:4 [▼
"default" => "smtp"
"mailers" => array:8 [▼
  "smtp" => array:8 [▼
    "transport" => "smtp"
    "host" => "in-v3.mailjet.com"
    "port" => 587
    "encryption" => "tls"
    "username" => "***"
    "password" => "***"
    "timeout" => null
    "auth_mode" => null
  ]
  "ses" => array:1 [▼
    "transport" => "ses"
  ]
  "mailgun" => array:1 [▼
    "transport" => "mailgun"
  ]
  "postmark" => array:1 [▼
    "transport" => "postmark"
  ]
  "sendmail" => array:2 [▼
    "transport" => "sendmail"
    "path" => "/usr/sbin/sendmail -t -i"
  ]
  "log" => array:2 [▼
    "transport" => "log"
    "channel" => null
  ]
  "array" => array:1 [▼
    "transport" => "array"
  ]
  "failover" => array:2 [▼
    "transport" => "failover"
    "mailers" => array:2 [▼
      0 => "smtp"
      1 => "log"
    ]
  ]
]
"from" => array:2 [▼
  "address" => "no-reply@pokeshares.com"
  "name" => "PokeShares"
]
"markdown" => array:2 [▼
  "theme" => "default"
  "paths" => array:1 [▼
    0 => "/var/www/pokeshares/resources/views/vendor/mail"
  ]
]
]

These look like the correct settings.

Any help is appreciated!

Lesley Peters
  • 409
  • 1
  • 5
  • 20
  • **only on the server, worked fine local** - Did you check your server firewall settings ? (does it allow outgoing port 587 connection ?) – Ken Lee Dec 27 '21 at 02:53
  • @KenLee checked it, but did not resolve the problem. – Lesley Peters Dec 27 '21 at 03:12
  • can you check your mail configuration what is getting from config? you can use this code inside controller before sending mail . dd(config('mail.smtp')); – Ariful Islam Dec 27 '21 at 04:11
  • @ArifulIslam doing this outputs the correct settings, so i don't think there is a wrong configuration. I have added the output in the main question. – Lesley Peters Dec 27 '21 at 13:26

0 Answers0