Skip to main content
Call us
  • Support Auckland: 9:00am~2:00am Monday~Friday(09) 975-9407
  • Support Countrywide (landline only) 9:00am~2:00am Monday~Friday0800 441 995
Phone numbers and hours
Help Center

Explore our online help resources

Help

Gen 4 VPS & Dedicated Servers Help

Enable PHPMail logging in Plesk Linux

You can isolate a script sending PHPMail() by using PHP's built-in mail log function. Plesk allows you to enable PHPMail() logs on a per domain basis or for multiple domains using the same version of PHP.

Enable for a single domain

  1. Login to Plesk.
  2. Select Websites & Domains from the menu on the left.
  3. Select the domain.
  4. Select PHP Settings.
  5. Scroll to the bottom and find the box that says Additional configuration directives. Add the directive to enable mail logs by specifying an absolute path to the log file and the file's name:

    mail.log = /var/www/vhosts/coolexample.com/phpmail.log
    

    Enter this into the Additional configuration directives box, and click Apply. If PHPMail() is used, a log file will automatically be created.

  6. Once a log file is generated, you can access this log from the Plesk file manager.

If you have SSH access, you can manipulate the data to find common scripts being used. To get started, you'll need to enable administrator access on your Gen 3 or Gen 4 server (if you haven't already done so), connect with SSH and switch to the root user.

Run the following to find scripts using PHPMail():

[root@server ~]# cat /var/www/vhosts/coolexample.com/phpmail.log | awk '{print $6}' | cut -c 2- | uniq -c | cut -f1 -d':'

   1255 /var/www/vhosts/coolexample.com/httpdocs/wp-content/uploads/2020/05/spamscript.php
    544 /var/www/vhosts/coolexample.com/httpdocs/wp-content/morespam.php

Enable for multiple domains

Note: Enabling a PHPMail() log for all domains requires you to use SSH. If you are unfamiliar with SSH, use the single domain instructions.

  1. Login to Plesk.
  2. From the Plesk home page, click Tools and Settings.
  3. Select PHP Settings.


  4. Select the version of PHP that you want to generate a log for. Our site runs PHP 7.3 as an FPM application.

  5. Select the tab that says php.ini
  6. Look for mail.log in the php.ini file. Remove the ;(semicolon) from the beginning of the line and specify where you'd like the PHP mail() log to be saved. Use the server's /tmp directory to avoid permission issues across domains.

  7. Select OK to save.
  8. Now, connect to your server with SSH and switch to the root user.
  9. Next, you need to create the mail log file and give it appropriate permissions so all Plesk subscriptions can write to it.

    [root@server ~]# touch /tmp/phpmail.log && chmod 777 /tmp/phpmail.log
    
  10. Once a log file is generated, you can parse the log for frequently used mail scripts.
    cat /path/to/phpmail.log | awk '{print $6}' | cut -c 2- | uniq -c | cut -f1 -d':'
    

Warning: Disable logging when you are finished! If not stopped, PHPMail logging will continue indefinitely and potentially max out your server's disk space.

Related steps

More info

  • Our server experts can perform these steps for a fee. For more information about our Expert Services, please visit our Expert Service menu.

Community Related

johnny-ttg's Avatar
mod_rewrite module NOT loaded

7 Replies

Last posted over 3 years ago.

diresu's Avatar
How Do I Enable HTTP/2 For My Website?

9 Replies

Last posted almost 3 years ago.

WorldHealthSite's Avatar
mod_rewrite module on Windows Hosting (Plesk)

1 Replies

Last posted over 4 years ago.

Don't see what you are looking for? Search the Community