Cannot send mail via PHP script: mail() has been disabled for security reasons

Created:

2017-07-26 06:57:43 UTC

Modified:

2017-08-16 17:00:35 UTC

0

Was this article helpful?


Have more questions?

Submit a request

Cannot send mail via PHP script: mail() has been disabled for security reasons

Applicable to:

  • Plesk for Linux

Symptoms

Cannot send mail via PHP script. The following error can be found in the domain's error log:

# grep mail /var/www/vhosts/system/example.com/logs/error_log
[proxy_fcgi:error] [pid 16465:tid 140511432062720] [client 203.0.113.2:51330] AH01071: Got error 'PHP message: PHP Warning: mail() has been disabled for security reasons in /var/www/vhosts/example.com/httpdocs/script.php on line 3\n'

Cause

PHP function mail() is disabled in php.ini

Resolution

  1. Check what PHP handler is enabled in Home > Domains > example.com > PHP Settings . Let it be PHP 5.6
  2. Check that disable_functions is enabled:

    # grep mail /opt/plesk/php/5.6/etc/php.ini | grep disable
    
    disable_functions = curl_multi_exec,dl,exec,passthru,proc_open,proc_close,shell_exec,show_source,symlink,system,mail,show_source, popen
  3. Connect to the server as root user via SSH

  4. Open php.ini file with text editor, e.g:

    # vi /opt/plesk/php/5.6/etc/php.ini
    
  5. Find the line with disable_functions and delete mail function from the list of disabled functions.

If it is required to enable mail function only for the one particular domain, add the following line in "Additional configuration directives" field in Home > Domains > example.com > PHP Settings to override main php.ini directives:

disable_functions=""
Have more questions? Submit a request
Please sign in to leave a comment.