Docker: Enabling mailing in php:apache (running WordPress)

Starting from

When using the php:apache image from image mail support was not enabled. On my docker host postfix is already enabled and configured to accept and forward mails from my docker containers. So I should be able to send mails.

When I decided to install WordPress by myself, I ended up with this Dockerfile and did config stuff using a volume over /var/www/html:

At the end I realized that mails are not working. Php’s answer when asking for the sendmail_path is this:

And Php mail() result is this:

The manual approach first:

Entering the container:

Then installing sSMTP

and configuring it. Here is my ssmtp.conf

Changing the sendmail_path for Php is easy as there is no php.ini by now:

After restarting the Apache

Php is responding with a valid sendmail_path

Now Php mail() and also WordPress mailing is working fine ;-).

The new Dockerfile:

You need to have the above ssmtp.conf file to build the image.