I am trying to set up a development environment with Symfony running in Docker. Recently I installed the symfony/mailer package with the option to install a mailcatcher, which turned out to be axllent/mailpit.
However, when my code tries to send an email (I am just trying the registration form generated by symfony with user email verification), I get the following error:
Connection could not be established with host "127.0.0.1:1025": stream_socket_client(): Unable to connect to 127.0.0.1:1025 (Connection refused)
However, if I try in console, using
symfony console mailer:test [email protected]
or
mailpit sendmail -t -S 127.0.0.1:1025 < email.txt
everything works fine and the email appears in the mailpit web UI (which I can access just fine on localhost:8025).
Here is the mailpit part of my compose.yaml:
mailer:
image: axllent/mailpit
restart: unless-stopped
volumes:
- ./mailer:/data
ports:
- 1025:1025
- 8025:8025
environment:
MP_SMTP_AUTH_ACCEPT_ANY: 1
MP_SMTP_AUTH_ALLOW_INSECURE: 1
MP_MAX_MESSAGES: 5000
MP_DATABASE: /data/mailpit.db
And in .env, I have the following DSN:
MAILER_DSN=smtp://127.0.0.1:1025
How do I make the code connect/send emails properly too?
If at all relevant, here is the full Stack Trace: