PHP mail() function test script

You can use this script to test the PHP mail() function on your server.

  1. Access file manager
  2. Navigate to the root folder of your website (public_html for primary domains. If not, access the addon folder assosciated with the domain name)
  3. Create a new file and save it as a .php file. Lets say test_mail.php
  4. Edit the file and add the following code to the file and save it
  5. <?php 
    ini_set( 'display_errors', 1 );
    error_reporting( E_ALL );
    // You will need to change the email address in the next two lines. You will need to update both 'from' and 'to' address. The email will be received at 'to' address
    $from = "";
    $to = "";
    $subject = "PHP Mail Test script";
    $message = "This is a test to check the PHP Mail functionality";
    $headers = "From:" . $from;
    if (@mail($to, $subject, $message, $headers)) {
       echo "Mail Sent Successfully";
       echo "Mail Not Sent";
    Please make sure you change the from address, to an email address assosciated with your cPanel account and the to address to any other email address that you have access to.
  6. Now you should be able to test the mail function by accessing
  7. If the mail function works, you will see a message that reads “Mail Sent Successfully” . If not, you will see “Mail Not Sent”.
  8. Cross check it by accessing your email setup in the ‘to’ folder to confirm that you have received the email. Make sure to check the spam folder as well.
    If you do not see the email, it could be that the outbound spam filter of your hosting provider has blocked your emails. You will have to contact them in such case for further troubleshooting.

    / /

    Report (Please include link to post while reporting)

Leave a Reply

Your email address will not be published. Required fields are marked *