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";
?>
Upload the file and test
- Place the file in your public_html folder or where ever the root of your site.
- Go to: somedomain.com/test-email.php
- Ensure you received the test email
Important: Don’t forget to delete the file when you’re done testing, it’s publicly available.