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

Spiral's avatar

Connection could not be established with host :stream_socket_client()

Connection could not be established with host  :stream_socket_client(): unable to connect to tcp://:0 (The requested address is not valid in its context.
) {"exception":"[object] (Swift_TransportException(code: 0): Connection could not be established with host  :stream_socket_client(): unable to connect to tcp://:0 (The requested address is not valid in its context.
MAIL_DRIVER=log
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

Does anyone have any ideas?

0 likes
11 replies
bugsysha's avatar

What are you trying to achieve?

If you want to send mails to mailtrap then I guess MAIL_DRIVER should be smtp. Also add your credentials. When you go to mailtrap you will see settings which you need to change for Laravel app.

If not, then explain.

1 like
Spiral's avatar

@bugsysha Thanks bro for replying i want to send in log file but give this error which i don't understant

Spiral's avatar

Also when i'm send to mailtrap with it's require field also get this error

bugsysha's avatar

Try deleting all from .env with MAIL_ prefix and only leave MAIL_DRIVER=log.

siangboon's avatar

The mail service should work out of the box once you created a laravel project, did you make any change on the config file or any core file? Suggest that create a new laravel project to test out whether is the particular project problem or your system problem....

Stack76's avatar

I have a fix for this guys:

I had the same problem and spent countless hours looking for an answer. I hope that I can help the community of developers by sharing the solution to the swift_transportexception connection issue. Here it is...

Make the following adjustment to your .env file:

MAIL_DRIVER=sendmail

MAIL_HOST=YOUR_DOMAIN.COM

MAIL_PORT=465

MAIL_USERNAME=YOUR_EMAIL@YOUR_DOMAIN.COM

MAIL_PASSWORD=YOUR_PASSWORD

MAIL_ENCRYPTION=ssl

MAIL_FROM_ADDRESS=YOUR_EMAIL@YOUR_DOMAIN.COM

MAIL_FROM_NAME="${APP_NAME}"

Make sure your DNS records is set to: MX - @ - mail.YOUR_DOMAIN.COM - Priority 0

If I have helped you solve the bug, please let us know by up-voting this answer to help others find peace.

~Newton Cazzaro

oopstack.com

3 likes
joybrusich's avatar

If you are using Mailtrap, just log in to your Mailtrap account, and copy and paste the Laravel SMTP settings into your .env file:

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=yourmailtrapusernamekey
MAIL_PASSWORD=yourmailtrapupasswordkey
MAIL_ENCRYPTION=tls
NickSmithTech's avatar

For those of you stumbling in here, also take note that MailTrap will invoke throttling (rate based on account level) if you send too many emails at one time which can cause connection errors.

szulczewskit's avatar

I know it's old topic but maybe someone is still struggling with this. Instead of MAIL_DRIVER=log u should set MAIL_MAILER=log

1 like

Please or to participate in this conversation.