PHP error guide
Cron PHP mail or PATH command fails: meaning and fix
Error summary
Use absolute command paths or a configured mail transport, check exit status, and do not rely on cron’s restricted PATH.
What it means
Use absolute command paths or a configured mail transport, check exit status, and do not rely on cron’s restricted PATH.
What the error means
A PHP mail transport or child process attempts to execute an external command that cron cannot resolve or that is not installed.
Why PHP produces it
The scheduled environment has a smaller PATH, while mail(), exec(), or a library delegates to a local binary.
PHP version notes
The behavior described for Cron PHP mail or PATH command fails applies to PHP 7.4–8.4 unless a narrower version is stated; exact wording can vary by SAPI and patch release.
Most common causes
- sendmail_path names a missing binary.
- exec calls a command by basename.
- The MTA is unavailable in a container or minimal host.
Minimal examples
BAD — reproduces the problem
@mail($to, $subject, $body);
FIXED — safer pattern
if (!mail($to, $subject, $body)) { throw new RuntimeException("Mail failed"); }
Step-by-step diagnosis
- Inspect ini_get("sendmail_path") with the cron PHP binary.
- Resolve every delegated command as the cron user.
- Check the function result, process exit code, and protected mail logs.
Fixes
Use a configured transport or absolute command
Configure a real mail transport and fail visibly when delivery cannot be queued.
$sent = mail($to, $subject, $body);
if (!$sent) {
throw new RuntimeException("Mail transport rejected the message");
}
Common mistakes when fixing it
- Treating mail() true as proof of final delivery.
- Adding insecure directories to PATH.
- Suppressing child-process stderr.
How to prevent it
- Health-check the configured transport.
- Use absolute executable paths.
- Monitor queue and task failures separately.
Web server / environment notes
cron, cli, linux. External transport availability can differ from web requests.
Tags: cron,cli,linux