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

anchan42's avatar

Setting Mailpit to work with Laravel.

I want to test email using mail pit but could not get is to work. I keep getting this error:

Connection could not be established with host "mailpit:1025": stream_socket_client(): php_network_getaddresses: getaddrinfo for mailpit failed: No such host is known.

I have mailpit running and can access the web interface. This is my env setup.

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

I try to change the host to 0.0.0.0 but it didn't work

0 likes
8 replies
NoLAstNamE's avatar

If you're having trouble setting up Mailpit, go for a simple solution. Use Mailtrap, it's so so easy to set up. That's what I always use.

2 likes
anchan42's avatar

Thanks you. I tried mailtrap and it work great but I still would love to be able to do this locally.

1 like
anchan42's avatar

I have figured it out. The setting that work for me is:

MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"
25 likes
thinkverse's avatar
Level 15

@cybert22 mailpit is set as the default to work with Laravel Sail, since Docker handles the resolution of the service. If you're not using Laravel Sail and Docker localhost must be used since your local machine cannot resolve the namespace.

4 likes
jamesbuch's avatar

@cybert22 localhost es el nombre de host predeterminado para su computadora. Si agrega más nombres de host como 'mailpit' a su C:\windows\system32\drivers\etc\hosts (agregue la línea 127.0.0.1 mailpit), ahora puede acceder a la interfaz de administración con, por ejemplo. http://mailpit:8025/.

eko3alpha's avatar

I just ran into this issue, wondering why http://localhost:1025 was not working. I looked at the docker-compose and found my answer

        ports:
        - '${FORWARD_MAILPIT_PORT:-1025}:1025'
        - '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025'

what you want is port 8025 to access the local web panel.

http://localhost:8025

DanielHemmati's avatar

For those who want to know why we use port 1025. port 8025 is for the web interface and port 1025 is smtp port. so this .env will work if you have docker instance of mailpit:

MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}

Please or to participate in this conversation.