using msmtp to send mail via php in docker container does NOT work in all cases

412 Views Asked by At

I am having issue making msmtp work in all cases when using php mail function. This is used in a docker container that relay's it to another docker container. It works in some cases but fails in others. See the php code for examples of when it fails/works.

msmtp version 1.8.22 Platform: x86_64-pc-linux-gnu

msmtprc config

host        postfix
remove_bcc_headers off
allow_from_override off (When OFF breaks both mail functions)

PHP CODE: I need both cases to work at once

$to = "[email protected]";
$subject = "My subject";
$txt = "Hello world!";
$from = '[email protected]';
$headers = "From: $from";

//1. Works with allow_overide_from on
//2. I get error when allow_overide_from off msmtp: account default from /usr/local/etc/msmtprc: envelope-from address is missing 

mail($to,$subject,$txt,$headers);

//Never works in either case (The php library I use does this and I do NOT want to modify core). (same error message with on/off for allow_overide_from)

//Error msmtp: cannot use both --from and --read-envelope-from
mail($to, $subject, $txt, $headers, '-f '.$from);

0

There are 0 best solutions below