After upgrading Matomo from 4.10.1 to 4.11.0 system fails sending email report.
System is configured to send email using PHP build in-mail function.
_$ ./console core:test-email <_myemailaddress_>_
succeed (no kind of error/warning, and email is regularly received). Instead sending report via admin web-page (Personal Email Reports => Send-Report-now) fails with generic error:
"An error occurred while sending 'HTML Email Report - 2.yesterday.1.en - XXXXX.html' to . Error was 'Could not instantiate mail function.'"
Original Matomo installation was 4.9 and then further updated. Problem is new since update to 4.11.0.
config.ini.php seems correct with expected config (including _noreply_emailaddress) and Matomo diagnostic does not report any kind of problem.
Has such behavior been noticed by others? Any further troubleshooting step to be performed? In the way problem appeared it seems related to performed upgrade.
Hi @x97-epe, thanks for reaching out.
If the console test-email command is successfully sending emails then it seems unlikely there is an issue with the Matomo email configuration. As far as I can see there haven't been any recent changes relating to mail delivery. I've also tested the 'Personal > Email Reports > Send Report Now' function and it's working for me.
"Could not instantiate mail function." is a generic message returned by PHPMailer when it is unable to deliver the mail to the system mail transport agent, which would match up with the lack of postfix activity.
A few things to try:
./console core:test-email <myemailaddress>command as the same user as the webserver (eg. www-data) does it still succeed?
Hi bx80! Thanks for feedback.
It seems to me PHP and email sub-system (postfix) are properly configured and work. In fact:
The problem seem to be connected to sending email via web-admin.
I actually find another similar report in forum when searching for "error crating new users":
It could be that email issues existed before 4.11, but we have not noticed it. I open present issue following a report my our web team complaining they failed to notify new users...
Hi @x97-epe, thanks for the extra information :+1:
I've checked the 'Send Report Now' and 'Invite User' web admin functions and they are using the same underlying code to send mail as the
./console core:test-email command. They both work consistently in my tests.
Typically the web server will not be running as the same Linux user as one used for scheduled reports (cronjob) and console commands, so different user permissions might an issue. From your tests we know that the PHP mail() command and system mail subsystem are working, it would be good to also confirm that the web server user can successfully send test emails.
Could you try to run the test email command as the web server user? (assuming the web server user is apache2 on RHEL)
sudo -u apache2 ./console core:test-email <myemailaddress>
I double check and process for httpd and php-fpm on RHEL8 run as user "apache". I run
sudo -u apache ./console core:test-email <myemail>
And it worked as expected.
Ok... I got it! It was SELINUX...
So obvious (now), but somehow I miss it. I finally noticed the logs generated into audit logs, I set SELINUX in permissive mode and emails are now sent via web... When set SEpolicy "httpd_can_sendmail" it works also with enable (enforcing) SELinux. Problem happened since such config was supposed to be already fix on server ("bug" into Ansible playbook script), and we notice issue at "wrong time" (i.e. right after Matomo update)
No problem with Matomo, case closed.
Glad you got it sorted! Thanks for letting us know :slightly_smiling_face: