[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[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')