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.