Sending mails from PHP within Docker with Mailhog

Mailhog is an excellent tool for isolated mail testing used in Docker. We set almost every project up to use it as email communication is still essential and might be hard and tricky to test.

Quite often we need to send emails from our dockerized application during the development and all messages - but without setting sendmail path dispatch errors might appear.

Therefore it's neccessary to set up the sendmail path in the php.ini file.

sendmail_path = /usr/sbin/sendmail -S {put your sendmail docker name here}:1025 -t

The 1025 is defined port where sendmail tries to send messages to. Feel free to change it accordingly. Using this setup you don't need mhsendmail (which is a sendmail for mailhog) anymore and you can use the standard mail() function.

You can get Mailhog container here

You may also like

 16.5.2021
Unit testing Magento 1

Writing unit tests for Magento 1 running in Docker Container

 23.5.2023
An error "Missed phrase" during Magento 2 phrase collection

Exception during phrase collection

 29.3.2022
Debugging Magento CLI running in Docker container

Debugging Magento CLI running in Docker container

 29.12.2022
XSD validation in your IDE

Validate your XML files against Magento 2 XSD schemas

 5.4.2023
Magento release 2.4.6 - what's new

New release of Magento 2

 3.5.2023
Mailhog PHP sendmail path configuration

Sending mails from PHP within Docker with Mailhog

 5.7.2023
Our Pimcore 11 upgrade notes

What we learned during upgrading Pimcore 10.x to 11.x