Skip to content

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.4.mail.log

where 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 $to argument to the mail() function.
  • The email headers, including the $additional_headers argument to the mail() function.
  • The $subject argument to the mail() 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 email

Example 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):

Terminal window
wc -l log/APPNAME/*.mail.log

Count 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):

Terminal window
sudo wc -l /srv/users/*/log/*/*.mail.log

View 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):

Terminal window
tail -n 100 log/APPNAME/*.mail.log