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

ekpono's avatar
Level 12

Connection could not be established with host smtp.mailtrap.io [Connection refused #111]

Connection could not be established with host smtp.mailtrap.io [Connection refused #111] on live server. Here is my credentials

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=my-username
MAIL_PASSWORD=mypassword

Please help out it is urgent. Have cleared config. Have also optimize:clear

0 likes
47 replies
Cronix's avatar

That works for me. The only addition I have is MAIL_ENCRYPTION=null

You'd also need to make sure that outgoing port 2525 is allowed through any firewalls your server might be behind.

Not sure why you'd be using mailtrap in production though...

1 like
Cronix's avatar
Cronix
Best Answer
Level 67

Did you check whether you're behind a firewall that's blocking outgoing port 2525?

D9705996's avatar

you can test if the port is available through your firewall using nmap from the command line on your server

 nmap -Pn -pT:2525 my-domain-name.com

Starting Nmap 7.01 ( https://nmap.org ) at 2018-10-11 18:56 BST
Nmap scan report for my-domain-name.com (52.55.164.156)
Host is up.
Other addresses for my-domain-name.com (not scanned): 52.5.251.20
rDNS record for 52.55.164.156: ec2-52-55-164-156.compute-1.amazonaws.com
PORT     STATE    SERVICE
2525/tcp filtered ms-v-worlds

Nmap done: 1 IP address (1 host up) scanned in 8.16 seconds

You need to see the STATE as open and not filtered or closed.

Obviously replace the my-domain-name.com with your real domain name

ekpono's avatar
Level 12

On ssh it is am having $ nmap -Pn -Pt:2525 koboaccountant.com -bash: nmap: command not found

Cronix's avatar

You just need to install it. How to do that depends on the os you're using, but here's how on CentOS/Debian/Ubuntu. Most others will also use one of those depending on what linux it was based off of:

  1. CentOS: yum install nmap
  2. Debian: apt-get install nmap
  3. Ubuntu: sudo apt-get install nmap
ekpono's avatar
Level 12

I am getting command not found in all the 3 commands

Cronix's avatar

Oh, if you're on windows, just temporarily disable the firewall and try your code again. If it works, then just create a new rule and allow port 2525 through.

D9705996's avatar

Just remember you must run the nmap command on the same server/pc as your laravel application

ekpono's avatar
Level 12

Still unable to send through mailtrap. Have installed nmap but in my command line, it doesn't recognize it.

Cronix's avatar

I want to receive the mail in [email protected].

You might also want to clarify that statement.

Mailtrap is for testing only. You can't send mail to a specific domain, like "my-domain-name.com". All email sent from your app will go to mailtrap, and you'll need to login to mailtrap to see them. It's not a real full blown email server. You can't use 3rd party tools to access it (like Thunderbird, Apple Mail, the email app on your phone, etc). It won't alert you when you receive a new email. You can't send emails from it. You can only receive emails, and you have to manually login to see if there are any. It doesn't sound like this is what you want to do from your quote? I'd hate to see you spending a bunch of time getting mailtrap to work if it won't actually do what you need it to do. It's just meant to test whether your app can send email out specifically to your mailtrap account (not some other domain). Nothing more.

ekpono's avatar
Level 12

@D705996

Starting Nmap 7.70 ( https://nmap.org ) at 2018-10-11 22:09 W. Central Africa Standard Time
Nmap scan report for www.koboaccountant.com (199.188.200.47)
Host is up.
rDNS record for 199.188.200.47: server239-2.web-hosting.com

PORT     STATE    SERVICE
2525/tcp filtered ms-v-worlds

Nmap done: 1 IP address (1 host up) scanned in 16.55 seconds
ekpono's avatar
Level 12

@Cronix thanks for the clearification. I want to forward the mail from mailtrap to [email protected]. At least i get notifications from there. @Cronix what the best option can you prefer. I need this up and running soonest. Thanks

Cronix's avatar

I'd use mailgun, sparkpost, or AWS SES for that, which are all supported out of the box like mailtrap is. Alternatively you can use gmail, but that's not really preferable and has other issues.

Are you only ever going to send emails to yourself, or will you be emailing users of your app as well? You'd need to be able to email users directly for things like email verification, password resets, etc.

D9705996's avatar

@ekpono - this is why it's not working. Something on your network is blocking access to port 2525 on www.koboaccountant.com.

However I tried with the standard SMTP port 25 and it is open. Try changing your env file from 2525 to 25 and let us know if it works

1 like
ekpono's avatar
Level 12

@D9705996 not still working

MAIL_DRIVER=smtp MAIL_HOST=smtp.mailtrap.io MAIL_PORT=25 MAIL_USERNAME=55cd6ac6e5e7bc MAIL_PASSWORD=ee968240f524b3 MAIL_ENCRYPTION=tls

ekpono's avatar
Level 12

Still getting this. Connection could not be established with host smtp.mailtrap.io [Connection refused #111]

MAIL_DRIVER=smtp MAIL_HOST=smtp.mailtrap.io MAIL_PORT=25 MAIL_USERNAME=55cd6ac6e**e7bc MAIL_PASSWORD=ee968240**24b3 MAIL_ENCRYPTION=tls

ekpono's avatar
Level 12

@Cronix mailgun is not sending verification code to my phone. That's where am stuck

D9705996's avatar

Yes because you have given the smtp server you were testing against as www.koboaccountant.com (in your nmap)

If you are trying to send mail via this server then you need to change

MAIL_HOST=smtp.mailtrap.io to MAIL_HOST=www.koboaccountant.com

You may also need to remove tls from MAIL_ENCRYPTION= but try with first.

This will allow you to send real emails (assuming the smtp server is configured correctly)

ekpono's avatar
Level 12

@D9705996 what should I do now? I am using shared hosting by the way. How can i resolve this

D9705996's avatar

First thing first we need to establish exactly what you are trying to achieve.

Are you actually trying to send real emails to users of your application?

If so you need a real mail server's details to use in your .env file not mailtrap. Do you have these for www.koboaccountant.com or is this your webserver that's serving your application?

ekpono's avatar
Level 12

@D9705996 thanks so much for your reply. I have hosted the site on namecheap. I want it that when a user signsup on the platform I will get a notification to follow up the user base on the information given to me on the platform. I am using mailtrap (though i have tried mailgun, gmail and still getting the same error) so i can get the email. I also intend to automatically forward the mail to [email protected]

D9705996's avatar

So the first thing to do is locate in the documentation of your SMTP provider the hostname and port to use.

Then you can test from you application server whether you can connect across the network using nmap

nmap -Pn -pT:<SMTP_PORT> <SMTP_HOST>

Replace the placeholders from the documentation.

If the output shows the STATE as anything other than open the problem is 100% network so needs resolved. Start with your application server and disable the software firewall and retry the nmap. If this doesn't show open then your issue is with your network configuration. If this is in your control then you need to allow access on the smtp_port however you might need to contact your ISP as some of them block SMTP traffic.

Once you run an nmap test and it shows open update the settings in your .env file

MAIL_DRIVER=smtp
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=

Again these details will available in the documentation.

Then retry sending an email. It might not work first time but you at least should get a different error message we can work with

ekpono's avatar
Level 12

i'm getting this

 nmap -Pn -pT:2525 smtp.mailtrap.io
Starting Nmap 7.70 ( https://nmap.org ) at 2018-10-11 23:32 W. Central Africa Standard Time
Nmap scan report for smtp.mailtrap.io (34.194.188.188)
Host is up (0.19s latency).
Other addresses for smtp.mailtrap.io (not scanned): 34.199.205.108 52.203.151.210
rDNS record for 34.194.188.188: ec2-34-194-188-188.compute-1.amazonaws.com

PORT     STATE SERVICE
2525/tcp open  ms-v-worlds

Nmap done: 1 IP address (1 host up) scanned in 7.63 seconds

ekpono's avatar
Level 12

i have ssh into my server and perform the same command but am getting -bash error

D9705996's avatar

@ekpono - this is for mailtrap. Are you sure this is what you want to use? It's not a real mail server and only meant for testing. You can only send 2 emails/second, have up to 50 mails in your "mailbox" and can't forward emails.

D9705996's avatar

@ekpono - so your not running your server on Windows then. What bash error are you getting? What operating system is you server running?

Next

Please or to participate in this conversation.