suteam's avatar

Connection could not be established with host "mailpit:1025": stream_socket_client(): php_network_getaddresses: getaddrinfo for mailpit failed: nodename nor servname provided

I have this docker service:

mailpit:
    image: "axllent/mailpit:latest"
    profiles: [app]
    ports:
        - "1025:1025"
        - "${FORWARD_MAILPIT_PORT}:8025"

I have this settings in .env

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

I have error during seding email:

[2024-01-10 20:49:59] local.ERROR: Connection could not be established with host "mailpit:1025": stream_socket_client(): php_network_getaddresses: getaddrinfo for mailpit failed: nodename nor servname provided, or not known {"exception":"[object] (Symfony\Component\Mailer\Exception\TransportException(code: 0): Connection could not be established with host "mailpit:1025": stream_socket_client(): php_network_getaddresses: getaddrinfo for mailpit failed: nodename nor servname provided, or not known at vendor/symfony/mailer/Transport/Smtp/Stream/SocketStream.php:154) [stacktrace] #0 [internal function]: Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream->Symfony\Component\Mailer\Transport\Smtp\Stream\{closure}(2, 'stream_socket_c...', 157)

0 likes
2 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@suteam I believe you can access the mailpit service via localhost:8025. If so, then you need to tweak your env value of MAIL_HOST and MAIL_PORT.

It should be like this:

MAIL_HOST=127.0.0.1
MAIL_PORT=1025

Don't forget to run php artisan config:cache to clear the cache.

3 likes
suteam's avatar

Thank you Sir. It is working fine

1 like

Please or to participate in this conversation.