How To Send E-mails From Server – Sample Test

Here is simplest script for sending emails from your server.This is the simplest emailer you can use and have in PHP.

If this does not work, then the PHP email configuration is bad!

First declare a variable for status message.which will be used to show message for your email send or not.

<br />
<br />

replace below with an email address that belongs to the website where the script is uploaded.For example, if you are uploading this script to, then an email like is good.

$from = ""</p>
<p>$to = "" //<-- put your yahoo/gmail email address here --></p>
<p>$subject = "Test Subject"<br />
$message = Test Message</p>
<p>$headers = From: $from; <br />
$headers .= Reply-To: $from; <br />
$headers .= Return-Path: $from;<br />
$headers .= X-Mailer: PHP <br />

and now the time for using simple php mail function.


if(mail($to_add,$subject,$message,$headers))<br />
{<br />
$msg = "Mail has sent";<br />
}<br />
else<br />
{<br />
$msg = "Error sending email!";<br />
}<br />

now the only last thing you have to do is a simple on button html page.which will be used to show status message when you press that button.

DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""><br />
<html><br />
<head><br />
<title>Sample email test sample</title><br />
<p><body><br />
<?php echo $status ?><br />
<p><br />
<form action='<?php echo htmlentities($_SERVER['PHP_SELF']); ?>' method='post'><br />
<input type='submit' name='submit' value='Submit'><br />
</form><br />
<p></body><br />

Now here is one thing if your email working its means that everything fine with your server.but if its not working you should check your SMTP configurations.