SOLVED! Solution: adjust sendmail_path value in php_cli/php.ini as well.
I'm running PHP 7.4 on Ubuntu 20.x
I've installed msmtp in order to send emails with php.
Problem: running mailtest.php from browser does work. running mailtest.php by a cronjob doesn't work, I get this error in my logfile.
sh: 1: /usr/sbin/sendmail: not found
problem:
Here's the line from my /etc/crontab
00 23 * * * root /usr/bin/php /var/www/mailtest.php >> /var/log/mails.log 2>&1
mailtest.php
$header = 'From: '.$mail_from. "\r\n" . 'Reply-To: '.$mail_from."\r\n" ;
if ($mailstatus = mail($mail_to, $mail_subject, $mail_body, $header)){
echo "sent";
} else {
echo "problem: ".$mailstatus;
}
It's probably some kind of permission issue I guess. I've already tried to change root -> www-data but in this case nothing happens at all, my mails.log-file stays empty. No Mail sent as well.
This is driving me nuts, I spent hours of googeling and really don't understand what is going on.
Any ideas? Any further details/stuff I can check?
Thank you very much for your time!