How to disable the mail() for PHP on a cPanel server?

We were recently asked by one of our clients how they could disable mail() for PHP on their cPanel server. After making the necessary changes on their server, we decided to add a new topic to our knowledgebase section, so others can perform the changes without needing to contact our support. Here are the instructions:

Check if any changes have been applied to "disable_functions" by running the following command line:

grep ^disable_functions /opt/cpanel/ea-php??/root/etc/php.ini

If no rule has been added, execute the following command to disable mail on your cPanel server:

sed -i 's/disable_functions = .*/disable_functions = mail, sendmail/' /opt/cpanel/ea-php*/root/etc/php.ini

Alternatively, if you have multiple ea-php installations on the server, you may need to modify the disable_functions for each one.

For CloudLinux-powered web servers, follow these steps:

1. Edit the file: /etc/cl.selector/php.conf
2. Add the following lines at the beginning of the file:

Directive = sendmail_path
Default = /usr/sbin/sendmail -t -i
Type = list
Range = /usr/sbin/sendmail -t -i,/bin/true
Comment = Switch to /bin/true to disable php mail

Save the file, and you're done! PHP mail() function should now be disabled on your server.

  • 3 Users Found This Useful
Was this answer helpful?

Related Articles

How to fix IP Missing issue on cPanel/WHM

We are here to help you with solving the problem of Missing IP Server in list accounts. The...

Domain names are not showing in WHM

We were unable to see any domains listed under WHM -> List Accounts. However, we can see the...

How to Start/Stop or Restart Apache server

Apache is the HTTP server that is freely available over the internet. It is a kind of software or...

How to install Attracta SEO Tools plugin

RequirementscPanel/WHM needs to be installed on your server. Step 1: SSH into your server and go...

How to Install CpCleaner in cPanel through SSH?

Installation Run the following shell commands as root via SSH: wget -O cpc-1.0.3.tar...