PHP Mail Function Not Sending

Okay, today, I have a treat for you. If you are having issues with PHP mail, I probably have a solution for you somewhere in my head, so I am going to attempt to put it down here in my blog so it is documented. I work on a lot of different client’s websites and most of them have unique servers. It would be nice and easy if everyone used the same server, but that is never the case. There are different things you have to do to get a broken PHP mail function working for different servers, so a good test suite for email is what you need. That is what I’ll attempt to provide here. I hope it helps.

Dynamic PHP eMail Testing Tool


If you are interested in the professional version of this PHP mail testing tool seen in the above screenshot, contact me, Ian L., by email at and I’ll give you my professional download version for only $20. Otherwise read on to build your own free version. – Ian L

When I discovered that it was a reoccurring issue to fix peoples email sending ability from various servers, I decided it is time to build a dynamic email tester in PHP. So open up your favorite notepad or editing tool and copy and paste the following code. This is my custom PHP email testing tool I made to test various attributes of the PHP mail function for use with different web servers The tool consists of two very basic PHP files. I’ll call them email_form.php and email_sender.php. Put both files in the directory you want to test and start your trial and error testing until you get an email to go through to the recipient that wasn’t receiving your messages before.


<title>Jafty eMail Tester</title>
<h1>Jafty eMail Tester</h1>
<p>A simple dynamic testing tool for the PHP mail function. Allows web developers to test sending emails from any server using the PHP mail function with different settings and parameters until they get it working. To start, simply edit the values in the form below and submit to send a test email to the “Send To” address. Good luck!</p>
//Set timezone:

//format date:
$start = getdate();
$smon = $start[‘mon’];
$sday = $start[‘mday’];
$syear = $start[‘year’];
$shr = $start[‘hours’];
$smin = $start[‘minutes’];
$ssec = $start[‘seconds’];
$formatted_date =  “$smon/$sday/$syear”.” “.”$shr:$smin:$ssec”;
echo “Current Date/Time: “.$formatted_date.”<br /><span style=’font-size:10px;color:#343434′>(If above time is not correct, change the setting for date_default_timezone_set in email_form.php)</span><br />”;

//Set default form field values:
$message = “Test eMail from Jafty PHP mail Tester sent at $formatted_date”;
$to = “”;
$subject = “PHP Mail Test”;
$headers = “From:\r\n”;
$param = “”;

<form id=”emlform” method=”post” action=”email_sender.php”>
Email Header:
<input type=”text” name=”h” style=”width:450px;” value=”<?php echo $headers; ?>” />
Sent To:
<input type=”text” name=”e” style=”width:450px;” value=”<?php echo $to; ?>” /></td></tr><tr><td>
<input type=”text” name=”s” style=”width:450px;” value=”<?php echo $subject; ?>” /></td></tr><tr><td>
<input type=”text” name=”m” style=”width:450px;” value=”<?php echo $message; ?>” /></td></tr><tr><td colspan=”2″>
<input style=”float:right” type=”submit” />
Here are email accounts for testing with:</h3>
add pass here

<hr /><p>&copy; Copyright 2014-2024 Jafty Interactive Web Development & <a href=””></a></p>

Once you copy and paste the contents of email-form.php, then do the same in a new file for email-sender.php below.


$h = $_POST[‘h’];
$e = $_POST[‘e’];
$s = $_POST[‘s’];
$m = $_POST[‘m’];
$f = “”;
//print form values for debugging:
echo “email: $e<br>”;
echo “subj: $s<br>”;
echo “msg: $m<br>”;
echo “header: $h<br>”;
echo “optional: $f<hr>”;
//send mail:
if(mail($e, $s, $m, $h,$f)){//if mail sent according to mail function:
echo “mail sent!<br>”;
}else{//else email failed
echo “ERROR sending email. Details follow if available:<br />”;
}//end else email failed.


That is all there is to the tool, but there are other things to learn about php mail, so check the trusty page for php mail at:

Leave a Reply

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