0

I'm running a multi-site setup with nginx and php-fpm 7.4 on Ubuntu 16.04. All sites are chrooted and everything runs like a charm. Except mail() over sendmail. (php-fpm version should not matter here, I'm struggling with this since 7.1).

Sendmail and postfix are running and configured. This line sends an email.

echo "Subject: sendmail test" | /sbin/sendmail -t -i root@example.com

Trying "the same" via PHP does not work:

mail("foobar@gmail.com","Testing","It's a test.", "root@example.com");

Does not work. mail() returns false. The mail log (/var/log/mail.log) remains empty. I configured log for sendmail with

php_value[mail.log] = /logs/mail.log

This log shows the call, e.g.

[16-Oct-2020 21:17:46 Europe/Berlin] mail() on [/htdocs/mail.php:8]: To: foobar@gmail.com -- Headers: root@example.com -- Subject: Testing

I also installed mini_sendmail (https://acme.com/software/mini_sendmail/), latest version, because I realised that sendmail requires a dozen files that I had to mount into my chrooted folders. So I downloaded mini_sendmail, renamed it to sendmail and put it into the chrooted folder /var/nginx/example_com/usr/sbin/sendmail

Running thes script from the command line with php, php-cgi also works:

php-cgi mail.php
php-cgi mail.php

phpinfo() also shows, that everything is configured (sendmail-path). shell-exec and exec are allowed functions. /bin/sh is also within the chroot-jail. Everything seems to be okay.

Any ideas, what I'm missing here? I don't even get an error message, that could help me.

n.r.
  • 831
  • 1
  • 11
  • 30

1 Answers1

0

Same thing here with centos 7, nginx 1.18, php-fpm 7.4.

Sending mail from PHP web app (mantisbt) - nothing happened, all server logs were empty (nginx error.log, php-fpm error.log, maillog, messages, selinux audit, ...)

Sending from commandline was working fine:

php -r'mail("user@domain.tld", "Subject", "Body");'

SOLVED

We finally found out that an invalid sender email address (From:) caused the trouble. After fixing from address, everything is working fine.


Some helpful links:

PHP mail function not working on Centos server https://www.mantisbt.org/forums/viewtopic.php?f=3&t=15398

  • I also tried the sender-email-address-trick, without success. Would you mind being more precise about that? You provided the from-address as an argument for mail()? What does "invalid" mean? Didn't fit what email address, configured where? Thanks! – n.r. Jan 12 '21 at 08:46
  • Pse have a look at line 1362 in email_api.php https://github.com/mantisbt/mantisbt/blob/master/core/email_api.php#L1362 – Fredy Paquet Jan 13 '21 at 10:20
  • Invalid address means we passed the string "user.domain.tld" instead of "user@domain.tld" – Fredy Paquet Jan 13 '21 at 10:22