简体   繁体   中英

sendmail not working with chrooted php-fpm and nginx

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, eg

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM