Applicable to:
- Plesk for Linux
Question
-
How to disable mail() function for a spamming domain on Plesk server?
-
How to prevent e-mails from being sent via scripts through Sendmail?
Answer
Click on a section to expand
To disable PHP mail() function for a domain, follow the steps below:
-
Go to Subscriptions > example.com > Customize > PHP settings
-
Add
disable_functions = mail
string to the Additional configuration directives field: - Click OK button to apply changes
Note: Make sure that the corresponding subscription is locked, otherwise the global definitions of that subscription plan will be synced and the domain's specific configuration will be lost.
Warning: If
disable_functions = mail
is set, but 'mail' is not listed as disabled in Domains > example.com > PHP Settings > phpinfo (), check if some additional PHP modules are installed on the server. Additional PHP modules can overwrite
php.ini
settings for the domain.
In case Suhosin PHP module is installed, follow these steps:
-
Connect to the server via SSH and comment out
disable_functions
directive in Suhosin config in order not to override the same directives in domainsphp.ini
.# grep disable_function /etc/php.d/suhosin.ini
;disable_functions = -
Add additional PHP directive for domain:
CONFIG_TEXT: disable_functions = exec, system, mail
Note: If mail() function is disabled for PHP, but emails are still being sent by unidentified script, Sendmail can be disabled completely.
Usage of Sendmail utility can be disabled server-wide with the settings at:
- Log in to Plesk GUI > Tools & Settings > Mail Server Settings > Disable the option Allow scripts and users to use Sendmail
Or at Service Plan level:
- Log in to Plesk GUI > Service Plans > <service_plan_name> > Mail > Disable the option Allow scripts and users to use Sendmail
Or at Subscription level:
- Log in to Plesk GUI > Subscriptions > example.com > Outgoing mail control > Subscription > Change limits > Disable the option Allow scripts and users to use Sendmail
Additional Information
Also, it is possible to block all outgoing mail that is being sent by PHP scripts like PHPMailer by adding the following iptables rule (on RHEL/CentOS):
- Connect to the server via SSH
- Save the current iptables rules to the file:
# iptables-save > /root/pre_iptables_rules
- Add the rule that blocks all outgoing packets send by processes where the owner is not postfix excluding local connections from Webmail:
# iptables -I OUTPUT -m owner ! --uid-owner postfix -m tcp -p tcp --dport 25 ! -d 127.0.0.1 -j REJECT
- Install and enable necessary package:
# yum install iptables-services && systemctl enable iptables-services
- Save iptables rules to make the changes permanent:
# /sbin/service iptables save
Comments
2 comments
Thanks for the great article but it is not working in my case,
Hi Marc Vidal
I have already disabled the function Mail () from the PHP setting of a wide server, still, I can see that the user is able to send mail from the server to outside.
the typical things is here i have also disabled the mail service from the panel for this domain as well there is no mail id still user able to send mail from Plesk default user.
Please suggest on this, which is helpful
Hello Arvind,
Steps described in this article allows fully block mail. If users still can send that it is probably not fully applies or something else. Nevertheless to check the issue it is required to create ticket as it is not something that can be simple advised in comments:
https://support.plesk.com/hc/en-us/articles/213608509-How-to-submit-a-request-to-Plesk-support-
Please sign in to leave a comment.