[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



Hi ryan,

Well, I don't wish to resolve fights between option '--from' and the 'From:' line in the header: if the user gives both, one of the two should win, I don't really care which.

My actual problem is PHP!mail can be called two ways:

| mail ($to, $subject, $message, 'From: lzsiga@...445...');
| mail ($to, $subject, $message, '', '--from lzsiga@...445...');
| mail ($to, $subject, $message, '', '-flzsiga@...445...'); ## a variation of the previous one

and both should work. Problem is, the first one doesn't work without option --read-envelope-from,
the second doesn't work with option --read-envelope-from.

Other combinations:

| mail ($to, $subject, $message, 'From: lzsiga@...445...', '--from somthing@...447...');

In this case either of the two should 'win', or (if they differ) an error message should be produced


| mail ($to, $subject, $message, '', '');

And in the first case a default-from could be created, or rejected with an error message.


On 2017-09-12 14:37, ryan wrote:
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@...448.....

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