Wp_mail() called via wp-cli cron fails with "sh: 1: /usr/sbin/sendmail: not found" in development env

In the development environment i have a Wordpress cron job being run via wp cron event run --due-now that sends email via wp_mail() which fails with the error: sh: 1: /usr/sbin/sendmail: not found and no email shows up in MailHog.

$ file /usr/sbin/sendmail
/usr/sbin/sendmail: cannot open `/usr/sbin/sendmail' (No such file or directory)

While it appears Trellis doesn’t install /usr/sbin/sendmail on the development VM, the same job called via a page load does send the email and it shows up in MailHog as expected.

I’m new to Trellis and not very familiar with how the MailHog and Wordpress integration is setup by Trellis and was hoping someone has some ideas why this maybe occurring.


I managed to locate the cause. Turns out that php in installed with multiple php.ini files and in particular there is one for fpm and one for cli. The cli php.ini doesn’t seem to be configured by trellis (maybe it should be?).

So by adding the config sendmail_path = /opt/mailhog/mhsendmail to the cli php.ini file as it exists in the fpm php.ini file the mail arrives in MailHog and the error disappears. Like all things, its simple once you know how.


This topic was automatically closed after 42 days. New replies are no longer allowed.