Digital Garden

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:

  1. Install sendmail (apt install sendmail)
  2. Add {docker.ip} {docker.hostname}.localdomain {docker.hostname} to the host's hosts file.
  3. Add {docker.hostname}.localdomain localhost to the container's hosts file
  4. Create the file /usr/local/etc/php/conf.d/sendmail.ini and add a single line sendmail_path=/usr/sbin/sendmail -t -i
  5. Run service sendmail start from inside the container
  6. Restart apache, service apache2 graceful

Better yet bake this into the Dockerfile and docker-compose.

External References

Linked References