Skip to content

Instantly share code, notes, and snippets.

@marinsagovac
Last active March 29, 2021 19:37
Show Gist options
  • Save marinsagovac/34673716c757993cbb6be5b0c17c31ac to your computer and use it in GitHub Desktop.
Save marinsagovac/34673716c757993cbb6be5b0c17c31ac to your computer and use it in GitHub Desktop.
Mailhog + Symfony 3
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('send@example.com')
->setTo('recipient@example.com')
->setBody('You should see me from the profiler!')
;
$this->get('mailer')->send($message);
Create a file 'docker-compose.yml' add:
mailhog:
image: 'mailhog/mailhog:latest'
container_name: mailhog
restart: always
ports:
- '8025:8025'
- '1025:1025'
Run `` then `docker run mailhog/mailhog`.
Check process: ˙docker-compose ps˙.
Run mailbox: http://0.0.0.0:8025/#
Set configuration in Symfony:
Set configuration: `parameters.yml`:
mailer_transport: smtp
mailer_host: 127.0.0.1:1025
mailer_port: 1025
mailer_user: null
mailer_password: null
# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
port: '%mailer_port%'
spool: { type: memory }
@glauberportella
Copy link

One comment to clarify to others that use a Symfony container, set the host as the name of the mailhog container, i.e. with the configuration above, the symfony app using the mailhog host need to inform:

host: mailhog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment