Test that email works on a PHP server

If you’re unsure as to whether or not your PHP server is configured for sending email, then this simple script is for you. 

This script works for any PHP server, most notably WordPress, Drupal or Joomla hosting services. 

Create test-email.php

// FILE: test-email.php

<?php 
    ini_set( 'display_errors', 1 );
    error_reporting( E_ALL );
    $from = "john@somedomain.com";
    $to = "YOUREMAILADDRESS";
    $subject = "PHP Mail Test script";
    $message = "This is a test to check the PHP Mail functionality";
    $headers = "From:" . $from;
    mail($to,$subject, $message, $headers);
    echo "Email test sent";
?>Code language: PHP (php)

Upload the file and test 

  1. Place the file in your public_html folder or where ever the root of your site. 
  2. Go to: somedomain.com/test-email.php
  3. Ensure you received the test email

Important: Don’t forget to delete the file when you’re done testing, it’s publicly available.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.