3

I made a small test php script that sends an email like this:

$headers = 'From: ' . $_POST["from"];
if (mail ($_POST["to"], $_POST["subject"], $_POST["body"], $headers)) {
  echo "Mail sent";
} else {
  echo "Problem sending email";
}

This is working fine on a server with Postfix.

When trying with msmtp, it ignores the From and complains:

msmtp: account default from /etc/msmtprc: envelope-from address is missing

The content of the config file is:

# cat /etc/msmtprc

account default
host localhost
port 25

I tried to set a from in that file and it worked, but overwritted the From that I passed in php.

Thanks for your help

4

1 回答 1

5

I found it.

The documentation here says https://wiki.archlinux.org/index.php/Msmtp#Send_mail_with_PHP_using_msmtp :

Look for sendmail_path option in your php.ini and edit like this:

sendmail_path = "/usr/bin/msmtp -C /path/to/your/config -t"

Which of course didn't work. After looking at the possible arguments, I found the one that works:

sendmail_path = "/usr/bin/msmtp -C /etc/msmtprc -t --read-envelope-from"

Cheers

于 2017-02-23T01:08:08.380 回答