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.

<?php
$status="";
<br />
if(isset($_POST['submit']))
<br />
{

Important
replace name@yoursite.com below with an email address that belongs to the website where the script is uploaded.For example, if you are uploading this script to www.yoursite.com, then an email like info@yoursite.com is good.


$from = "info@naeemrana.com"</p>
<p>$to = "someone@gmail.com" //<-- 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.


<?php

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" "http://www.w3.org/TR/html4/loose.dtd"><br />
<html><br />
<head><br />
<title>Sample email test sample</title><br />
</head></p>
<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></p>
<p></body><br />
</html>

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.