PHP unable to mail() in chroot though I can use sendmail inside chroot

chrootphp-fpm

I'm building a php-fpm chroot, and am on one of my last steps before calling this a success.

The php-fpm chroot is working like a charm. Also, I have mini_sendmail installed into the chroot (in place of stock sendmail) and can confirm that it can send email:

[root@hostname site1.com]# ls bin/
bash  cat  sendmail  test.txt
[root@hostname site1.com]# chroot .
bash-4.2# cat /bin/test.txt | ./bin/sendmail -t -i -fme@site1.com me@my-email.com

I get the email when the above command is run.

However, when I access the following php script from a web browser, no email is sent:

<?php
    $message = "This is a test";
    $headers = 'From: me@site1.com';
    mail("me@my-email.com", "Test", $message, $headers);
    echo "mail sent";
?>

Below is my php-fpm chroot pool config file:

[site1.com]
user = user1
group = user1
listen = 127.0.0.1:9001
listen.owner = user1
listen.group = user1
php_admin_value[disable_functions] = exec,passthru,shell_exec,system
php_admin_flag[allow_url_fopen] = on
php_flag[display_errors] = on
php_admin_value[short_open_tag] = On
php_admin_value[doc_root] = www
php_admin_value[error_log] = /logs/php-errors
php_admin_flag[log_errors] = on
php_admin_value[sendmail_path] = /bin/sendmail
php_admin_value[mail.log] = /logs/maillog
php_admin_value[error_reporting] = E_ALL
pm = ondemand
pm.max_children = 5
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chroot = /home/www/site1.com
chdir = /www
catch_workers_output = yes

When I access the php file from a web browser, I can confirm that there's a log entry in the maillog as defined by the php_admin_value[mail.log]:

mail() on [/www/mailer.php:4]: To: me@my-email.com -- Headers: From: me@site1.com

However, nothing shows up on the server's maillog (outside of the chroot), and nothing shows up in the php error log.

How can I finish troubleshooting this last step of getting php's mail() function to work as desired in my php-fpm chroot? Or, how can I fix the actual problem?

Best Answer

I know this is quite an old question, but I found this as one of the hits while trying to solve the same issue and so in case anyone hits this in future there's another thing to check. In my case I was missing /bin/sh from the chroot environment.

php passes sendmail_path into popen. popen passes the command to /bin/sh and so if your chroot environment is missing /bin/sh you seem to get a failure with nothing logged