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

Simon Levesque
  • 417
  • 1
  • 6
  • 13

1 Answers1

6

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

Simon Levesque
  • 417
  • 1
  • 6
  • 13
  • Actually, if you install msmtp-mta too, sendmail will work out of the box and I have no issues specifying the FROM address in my call to mail(). I didn't even have to modify php.ini. I'm using PHP 7.4. – Omid Ariyan Jan 20 '21 at 18:58