@x97-epe opened this Issue on August 16th 2022

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.
Email troubleshooting:

_$ ./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.
Please note:

  • Matomo runs on RHEL8 using PHP 7.4 (Apache 2.4 + PHP-FPM)
  • No errors/warning in PHP-FPM or Apache logs
  • No activity into local postfix used for forwarding email (no request received from PHP, but when running console test )

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.

@bx80 commented on August 17th 2022 Contributor

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:

  • If you run the ./console core:test-email <myemailaddress> command as the same user as the webserver (eg. www-data) does it still succeed?
  • If you create a new simple email report with a simple name (eg. abc123) and attempt 'Send Report Now', does it succeed?
  • Do other emails sent from the Matomo UI work? Such as invite user or reset password?
@x97-epe commented on August 17th 2022

Hi bx80! Thanks for feedback.

It seems to me PHP and email sub-system (postfix) are properly configured and work. In fact:

  • ./console core:test-email works when using my email as well when sending to apache@localhost (end into (/var/spool/mail/root file).
  • I set a test email-report configured to be delivered at given time. I regularly get the report...

The problem seem to be connected to sending email via web-admin.

  • I cannot send report using "Send Report Now".
  • Reset Password and Invite new user routines fail

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...

@bx80 commented on August 19th 2022 Contributor

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>
@x97-epe commented on August 19th 2022


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.

@x97-epe commented on August 19th 2022

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.

@bx80 commented on August 21st 2022 Contributor

Glad you got it sorted! Thanks for letting us know :slightly_smiling_face:

This Issue was closed on August 20th 2022
Powered by GitHub Issue Mirror