Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

NinjaRashu's avatar

Connection could not be established with host "live.smtp.mailtrap.io:587": stream_socket_client(): Unable to connect to live.smtp.mailtrap.io:587 (Connection refused)

I have seen everywhere about this problem and found no solution.

I found in one discussion that if you put mail in "transport" configuration in "mail" config file it just works and dont know why it worked.

I have this setting in mail config file which does not work and gives the above error.

This error occurs only in production and not in local.

I am using Godaddy Hosting.

'mailers' => [ 'smtp' => [ 'transport' => 'smtp', 'host' => env('MAIL_HOST', 'smtp.postmarkapp.com'), 'port' => env('MAIL_PORT', 587), 'encryption' => env('MAIL_ENCRYPTION', 'TLS'), 'username' => env('MAIL_USERNAME'), 'password' => env('MAIL_PASSWORD'), 'timeout' => null, ],

My env config are

MAIL_MAILER="smtp" MAIL_HOST=live.smtp.mailtrap.io MAIL_PORT=587 MAIL_USERNAME=api MAIL_PASSWORD=sdfsdfdsfsdf MAIL_ENCRYPTION=tls [email protected] MAIL_FROM_NAME="${APP_NAME}" [email protected]

0 likes
6 replies
gych's avatar

Are you 100% sure that you're using the correct username and password?

Snapey's avatar

open tinker

type config('mail')

paste here the result

finally, be clear, are you trying to test with mailtrap or send production mail with postmark ?

NinjaRashu's avatar

@Snapey

This is the result of config('mail')

[ "default" => "smtp", "mailers" => [ "smtp" => [ "transport" => "smtp", "host" => "live.smtp.mailtrap.io", "port" => "587", "encryption" => "tls", "username" => "api", "password" => "sdfds", "timeout" => null, "local_domain" => null, ], "ses" => [ "transport" => "ses", ], "mailgun" => [ "transport" => "mailgun", ], "postmark" => [ "transport" => "postmark", ], "sendinblue" => [ "transport" => "sendinblue", ], "sendmail" => [ "transport" => "sendmail", "path" => "/usr/sbin/sendmail -bs", ], "log" => [ "transport" => "log", "channel" => null, ], "array" => [ "transport" => "array", ], "failover" => [ "transport" => "failover", "mailers" => [ "smtp", "log", ], ], ], "from" => [ "address" => "[email protected]", "name" => "PCS_SIMPLIFIED", ], "markdown" => [ "theme" => "default", "paths" => [ "/home/qfki1h43ne25/pcssimplified/resources/views/vendor/mail", ], ], ]

CamKem's avatar

@snapey Did you have any thoughts around this? I have just deployed a site that uses mailtrap as the mail provider & am getting the same exception when background jobs are sending mail.

I just copied and pasted the env details that Mailtrap provided.

@ninjarashu Did you find out what the issue was?

I can dig into it further or contact Mailtrap, I just figured i'd follow up here.

Snapey's avatar

when dealing with mail, you have to consider your hosting provider. Some are really cautious about letting you send email from their server and will block certain outbound ports, which I suspect is the issue in the original question with GoDaddy. If the same config works locally then its almost certainly a firewall issue at your hosting provider

btw, dont call out people in questions (apart from the OP) as other people think, oh, he doesnt want my opinion, ok.

Please or to participate in this conversation.