Mail sending not working on website with PHP-FPM and chroot

OS type and version Debian Linux 11
Webmin version 2.001
Virtualmin version 7.2-1
Related packages


I have an issue with outgoing email via Wordpres (not only wordpress) on a website when both PHP-FPM and chroot are enabled.
The email is not delivered to the MTA, I have no entry in the mail.log… Just nothing happens!

The setup PHP-FPM without chroot works fine.
The setup FCGId with chroot works fine too…

There is a way to send mail in the chrooted enviroment with PHP-FPM?

Thank you for your help.

Then nothing is reaching the mail server.

How are you trying to send mail? FPM and chroot are mostly irrelevant, though how you run PHP may determine which PHP modules you have available.

Since you’re sending from a web app and since you see nothing in the mail log, you need to look at the error log, mostly likely, but the application may also have a log.

HI Joe,

I know that :slight_smile:

The webapp is a simple wordpress website installed via Virtualmin script installer.

Also there is no error in the error log.

I used “WP mail SMTP” plugin to try to debug and I receive this log:

WordPress: 6.0.3
WordPress MS: No
PHP: 8.0.24
WP Mail SMTP: 3.6.1

Mailer: mail
Constants: No

PHP.mail(): Yes

PHPMailer Debug:
Could not instantiate mail function.

Email Source: WP Mail SMTP
Mailer: Default (none)
PHPMailer was able to connect to SMTP server but failed while trying to send an email.

If I change the PHP execution mode to FCGid or remove the chroot, everything works as expected…

seems like php mail function is disabled in chrooted fpm…

The chroot is not relevant. Apache and FPM do not run chrooted, even if the user shell does.

And, I don’t think this indicate mail is disabled, I think it indicates a misconfiguration. This error:

PHPMailer was able to connect to SMTP server but failed while trying to send an email.

Does not indicate anything is missing.

If the app is actually communicating with the local SMTP server, however, there should be something in the mail log. Which we’d need to see. Unless the app is configured to send somewhere else entirely, in which case, that needs to be corrected.

The app is vanilla WP installed via the virtualmin script installer.
The php-fpm .ini is almost default, I olny changed the memory, upload and timeout limits…
The server is freshly installed and this is the first vhost I activated.

There is no entry related to the transaction in the mail log…

I also tried a simple script to check the php mail() function (How to test and fix the php mail() function) and it return “Error: Message not accepted” but nothing in the mail log.
If I remove the chroot, the script works, I receive the the email and i can find the transaction in the mail.log

I also noticed that others 2 older servers (with debian 9 and latest virtualmin) that I manage, have the same issue.

Perhaps, the issue is more general, and your ISP is simply blocking port 25?

Nope, as I told before, if I remove chroot OR change the php execution to FCGid, the email works fine.
I also receive the emails sent by Virtulamin on server creation…

Perhaps, your app is using sendmail binary which is missing in chroot environment?

The best option would be is to send mail using SMTP directly.

It is the default behaviour of Wordpress… It uses php-mail() to send emails.
@Joe says that FPM do not run chrooted, but there is this line in php-fpm.ini

chroot = /home/chrooot/123454678900

Perhaps it means that it runs chrooted?

I know I can use some wp plugin to setup a different SMTP, but should be better to have something that works out of the box…
There is some setting in php-fpm.ini that can fix this?

Try adding sendmail program to your chroot env.

Ah, I guess I was wrong about FPM and chroot. Oops.

I have already looked into this, but it seems that you need a lot of libs to copy in the chrooted env.
I foud a couple of guides mentioning mini_sendmail (Sending Email from Chroot Environment – Ways of the nix's).

But I was hoping there was something easier :wink:

maybe this related to jailkit : jailkit howto - mail in a chroot jail

disclaimer : haven’t tried this at “home” - not using chroot.

Thank you @dimitrist I have already found this, but i think it is related to the delivery of the email in the ueser mailbox…

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.