title: Use PHP sendmail from Docker container to send through host Postfix
body: <p>I want to send mail from my Alpine-PHP-Fpm container using my host postfix installation.</p>
  <h3>RECAP</h3>
  <p>PHP-Fpm Container -&gt; Sendmail -&gt; PostFix on host -&gt; Sending via SMTP</p>
  <p>But I get</p>
  <blockquote>
  <p>sendmail: can't connect to remote host (127.0.0.1): Connection refused</p>
  </blockquote>
  <p>Here is the Postfix config:</p>
  <pre><code>smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
  biff = no
  append_dot_mydomain = no
  readme_directory = no
  
  smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
  smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
  smtpd_use_tls=yes
  smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
  smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
  
  smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
  myhostname = MYDOMAIN.com
  alias_maps = hash:/etc/aliases
  alias_database = hash:/etc/aliases
  myorigin = /etc/mailname
  mydestination = localhost.com, localhost
  
  # SMTP authentication settings
  smtp_sasl_auth_enable = yes
  smtp_sasl_password_maps = static:no-reply@MYDOMAIN.com:SECRETPSW
  smtp_sasl_security_options = noanonymous
  smtp_tls_security_level = may
  #header_size_limit = 4096000
  relay_destination_concurrency_limit = 20
  
  # Limit DOS Attacks
  default_process_limit = 100
  smtpd_client_connection_count_limit = 10
  smtpd_client_connection_rate_limit = 30
  queue_minfree = 20971520
  header_size_limit = 51200
  message_size_limit = 10485760
  smtpd_recipient_limit = 100
  
  # Default relayhost setting
  relayhost = smtp.MYDOMAIN.com
  
  mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 172.18.0.3 # Fpm container IP
  mailbox_command = procmail -a &quot;$EXTENSION&quot;
  mailbox_size_limit = 0
  recipient_delimiter = +
  inet_interfaces = 172.18.0.1 # Docker0 bridge IP
  inet_protocols = all
  </code></pre>
  <p>And here is the php.ini mail section:</p>
  <pre><code>[mail function]
  SMTP = localhost
  smtp_port = 25
  sendmail_path = &quot;/usr/sbin/sendmail -t -i&quot;
  mail.add_x_header = On
  </code></pre>
  <p>Are there any ports that I need to open in my docker-compose file or in the host firewall settings?</p>