How to configure cpanel hosting to use php mail

To configure cPanel hosting to use PHP mail, you'll need to make a few changes to your server settings and PHP configuration. Here's a step-by-step guide to help you achieve this:

Step 1: Enable PHP mail

  1. Log in to your cPanel account.
  2. Click on the "Software" tab.
  3. Click on "Select PHP Version" and select the version you're currently using (e.g., PHP 7.4).
  4. Click on the "Configure PHP" button.
  5. Scroll down to the "Mail" section and toggle the "Enable PHP mail" switch to "On".

Step 2: Configure PHP mail settings

  1. In the same "Configure PHP" page, scroll down to the "Mail" section.
  2. Set the following settings:
    • sendmail_path: /usr/sbin/sendmail -t -i
    • mail.add_x_header: On
    • mail.log: /var/log/maillog
  3. Click the "Save" button to apply the changes.

Step 3: Update your PHP configuration file

  1. Log in to your server using SSH (e.g., FileZilla).
  2. Navigate to the PHP configuration file: /etc/php.ini (or /etc/php7.4.ini if you're using PHP 7.4).
  3. Open the file in a text editor (e.g., nano or vim).
  4. Add the following lines at the end of the file:
    [mail]
    sendmail_path = /usr/sbin/sendmail -t -i
  5. Save the changes and exit the editor.

Step 4: Restart your PHP-FPM service

  1. Restart the PHP-FPM service to apply the changes: sudo service php-fpm restart (or sudo systemctl restart php-fpm on newer systems).

Step 5: Test your PHP mail configuration

  1. Create a new PHP file in your cPanel account (e.g., testmail.php).
  2. Add the following code to the file:
    <?php
    mail('[email protected]', 'Test Subject', 'This is a test email');
    ?>
  3. Save the file and upload it to your server.
  4. Access the file through your web browser (e.g., http://example.com/testmail.php).
  5. If everything is configured correctly, you should receive an email at the recipient's address.

That's it! Your cPanel hosting should now be configured to use PHP mail. If you encounter any issues or errors, feel free to ask, and I'll do my best to help you troubleshoot.