Use PHP sendmail from Docker container to send through host Postfix
I'm not sure about using the host's config/postfix however I can suggest an alternative solution that may work just as well. Add a postfix container and copy the configs from the host to the container:
services: application: image: some-company/some-application environment: - APPLICATION_ENV ports: - 80:80 smtp: image: namshi/smtp environment: - MAILNAME - SMARTHOST_USER - SMARTHOST_PASSWORD volumes: - /etc/postfix/main.cf:/etc/postfix/main.cf ports: - 25:25
Then you can use smtp
as your mailer host / transport and the user/pass from the environment.
I am not a container expert, but if I understood correctly, you are trying to acccess 127.0.0.1 within the container (php.ini localhost config resolves to 127.0.0.1), and I assume that is not the hosts address, it points to the container internals.
Figure out the host IP and change in the php.ini:
[mail function]SMTP = host_addresssmtp_port = 25
The best solution which I have found is to install msmtp and add the following to the php.ini
sendmail_path = /usr/bin/msmtp -t --host host.docker.internal --from php@docker
Now your mail will be received by your mail server (smpt4dev or mailh