PHP Sendmail in Docker
Step by step guide for getting sendmail configured in a docker container so
the php mail
function can send from inside the container for development
testing. This is using the php:7.3-apache
image:
- Install sendmail (
apt install sendmail
) - Add
{docker.ip} {docker.hostname}.localdomain {docker.hostname}
to the host's hosts file. - Add
127.0.0.1 {docker.hostname}.localdomain localhost
to the container's hosts file - Create the file
/usr/local/etc/php/conf.d/sendmail.ini
and add a single linesendmail_path=/usr/sbin/sendmail -t -i
- Run
service sendmail start
from inside the container - Restart apache,
service apache2 graceful
Better yet bake this into the Dockerfile
and docker-compose
.
External References
- Butler, Tom. How to get sendmail working in docker PHP, Tom Butler's programming blog. Retrieved 2020-10-23.
- stuartz-VernonCo. mail() does not work out of the box, Github docker-library/php. Retrieved 2020-10-23.