PHP app mail logs
An app’s PHP mail log contains records of every time the app called
PHP’s mail() function.
When a PHP script calls the mail(), PHP hands off the email to Postfix.
Postfix is the Mail Transfer Agent (MTA) running on your server.
Postfix delivers the email to the recipient’s mail server.
As calls to PHP’s mail() function may include multiple recipient addresses in CC and BCC headers,
a single log entry in an app’s PHP mail log can represent multiple emails sent by your server.
View the logs
An app’s PHP mail logs can be viewed from within the ServerPilot dashboard or through SSH.
Log file location
Relative to the home directory of the app’s system user, the path to an app’s PHP mail log is:
log/APPNAME/APPNAME_php8.5.mail.loglog/APPNAME/APPNAME_php8.4.mail.loglog/APPNAME/APPNAME_php8.3.mail.loglog/APPNAME/APPNAME_php8.2.mail.loglog/APPNAME/APPNAME_php8.1.mail.loglog/APPNAME/APPNAME_php8.0.mail.loglog/APPNAME/APPNAME_php7.4.mail.loglog/APPNAME/APPNAME_php7.3.mail.loglog/APPNAME/APPNAME_php7.2.mail.loglog/APPNAME/APPNAME_php7.1.mail.loglog/APPNAME/APPNAME_php7.0.mail.loglog/APPNAME/APPNAME_php5.6.mail.logwhere APPNAME is the name of the app.
Log file format
Each log entry includes:
- The date and time when the app called the
mail()function. - The filename of the script that called the
mail()function. - The
$toargument to themail()function. - The email headers, including the
$additional_headersargument to themail()function. - The
$subjectargument to themail()function.
For example, an entry in an app’s PHP mail log will look like:
[03-Dec-2024 18:34:44 UTC] mail() on [/srv/users/SYSUSER/apps/APPNAME/public/wp-includes/class-phpmailer.php:698]: To: recipient@example.com -- Headers: Date: Sun, 3 Dec 2024 18:34:44 +0000 From: Example Sender <sender@example.com> Reply-To: Example Sender <sender@example.com> Message-ID: <3160605006c199f790086ba4b4fbc085@example.com> MIME-Version: 1.0 Content-Type: text/html; charset=UTF-8 -- Subject: this is an example emailExample commands
Count calls to mail()
Count the number of times an app called PHP’s mail() function since
the most recent log rotation (replace APPNAME with the name of the app):
wc -l log/APPNAME/*.mail.logCount the number of times every app on a server called PHP’s mail() function since
the most recent log rotation (requires logging in as root):
sudo wc -l /srv/users/*/log/*/*.mail.logView recent calls to mail()
View the 100 most recent entries in an app’s PHP mail log
(replace APPNAME with the name of the app):
tail -n 100 log/APPNAME/*.mail.log