[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [msmtp-users] msmtp with PHP!mail -- problem with --from and --read-envelope-from
I have encountered a similar issue with cron. I could not find the reason in any post only and ended finding my answers in the source code of cron and msmtp.
If the sending application included a from header in the email this will take precedence and Msmtp will not overwrite this. you will need to find a way to change the from header in PHP
-----Original Message-----
>From: Lorinczy Zsigmond <lzsiga@...444...>
>Sent: Sep 12, 2017 7:27 AM
>To: msmtp-users@lists.sourceforge.net
>Subject: [msmtp-users] msmtp with PHP!mail -- problem with --from and --read-envelope-from
>
>Hi,
>
>I'd like to report a problem / suggest an impovement regarding PHP!mail
>and msmtp.
>
>I wished to use mstmp with PHP so I added it into /etc/php.ini:
>
>| sendmail_path = "/usr/local/bin/msmtp -t"
>
>and tried this script
>
>| mail ($to, $subject, $message, 'From: lzsiga@...445...');
>
>Well it didn't work, it missed the 'From' header:
>
>| msmtp.bin: account default from /usr/local/etc/msmtprc: envelope-from
>address is missing
>
>So I added option '--read-envelope-from':
>
>| sendmail_path = "/usr/local/bin/msmtp.bin --read-envelope-from -t"
>
>Then my script did work, but some other user/project (kanboard, to be
>precise)
>used another way to specify the 'From:' header
>
>| mail ($to, $subject, $message, '', '--from lzsiga@...445...');
>
>Now it resulted in this:
>
>| /usr/local/bin/msmtp.bin --read-envelope-from -t --from lzsiga@...445...
>
>Which lead to this error message:
>
>| msmtp.bin: cannot use both --from and --read-envelope-from
>
>Then I hacked a very ugly workaround:
>
>| #!/bin/sh
>| HasFrom=
>| for Arg in "$@"; do
>| if [ "$Arg" = "--" ]; then
>| break;
>| fi
>| if [ "$Arg" = "--from" ]; then
>| HasFrom=1;
>| break;
>| fi
>| done
>| if [ -z "$HasFrom" ]; then
>| exec /usr/local/bin/msmtp.bin --read-envelope-from "$@"
>| else
>| exec /usr/local/bin/msmtp.bin "$@"
>| fi
>
>Well, I don't think it is a solution;
>what I'd would to suggest is something like this:
>
>If option '--from' is given, it's value is used as 'Envelope-From'
>Otherwise if there is a 'From:' line in the header, that value is used
>Otherwise a default 'From' is created based on the configuration files
>
>If you think this makes sense, I'd be happy to work in this improvement.
>
>Yours: Lőrinczy Zsigmond (user 'lzsiga' in 'souceforge.net')
>
>
>------------------------------------------------------------------------------
>Check out the vibrant tech community on one of the world's most
>engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>_______________________________________________
>msmtp-users mailing list
>msmtp-users@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/msmtp-users