Call Us: 992 9441 754

Fix PHP Mail() Not Working in cPanel Hosting – Easy Guide

< All Topics

Fix PHP Mail() Not Working in cPanel Hosting – Easy Guide

If the PHP mail() function is not working on your cPanel hosting, there are several potential issues to consider and steps you can take to troubleshoot and resolve the problem. Here’s a comprehensive guide to help you diagnose and fix the issue:

Steps to Troubleshoot and Fix PHP mail() Function Issues

1. Check Basic PHP Configuration:

  • Ensure mail() Function is Enabled:
  • Check if the mail() function is enabled in your PHP configuration. You can create a PHP info file to see the PHP configuration:
    <?php phpinfo(); ?>
  • Look for the disable_functions directive. If mail is listed there, it means the function is disabled.

2. Verify Email Configuration in cPanel:

  • Check Email Routing:
  • In cPanel, go to the Email section and click on Email Routing. Ensure that it is set correctly for your domain (e.g., Local Mail Exchanger if you are using the hosting server to send emails).

3. Test the mail() Function:

  • Create a simple PHP script to test the mail() function:
  • Upload this script to your web server and run it by accessing it through a web browser. This will help you determine if the mail() function works.

4. Check Email Logs:

  • Review the email logs for any errors or issues related to sending emails. The logs are typically located at /var/log/exim_mainlog if you have access to SSH:
  • If you don’t have SSH access, you might need to contact your hosting provider for log access.

5. Ensure Correct DNS Settings:

  • Verify that your domain’s DNS settings are correct, especially the MX (Mail Exchange) records, to ensure proper email delivery.

6. SPF and DKIM Records:

  • Ensure that your domain has proper SPF (Sender Policy Framework) and DKIM (DomainKeys Identified Mail) records set up. These records help authenticate your emails and improve delivery success.

7. PHP Mail Configuration in php.ini:

  • Check the php.ini configuration for the sendmail_path directive. It should be correctly set to the path of the sendmail binary or equivalent mail transfer agent (MTA).

8. Use an SMTP Server:

  • If the mail() function continues to fail, consider using an SMTP server for sending emails. This is often more reliable and can provide better logging and error handling. You can use PHPMailer or another library to send emails via SMTP. Example using PHPMailer:


By following these steps, you should be able to identify and resolve the issue with the PHP mail() function not working on your cPanel hosting. If the issue persists, it may be beneficial to contact your hosting provider for further assistance, as they can provide more specific insights and support based on your hosting environment.


Recent Comments

No comments to show.