/*---------- Validation Script ---------------*/
<script>
function validateForm()
{
var x=document.forms["myForm"]["name"].value;
if (x==null || x=="")
{
alert("Name must be filled out");
return false;
}
var y=document.forms["myForm"]["contact"].value;
if (y==null || y=="")
{
alert("Contact must be filled out");
return false;
}
var z=document.forms["myForm"]["address"].value;
if (z==null || z=="")
{
alert("Address must be filled out");
return false;
}
var m=document.forms["myForm"]["msg"].value;
if (m==null || m=="")
{
alert("What is your message? Please write in message field.");
return false;
}
var e=document.forms["myForm"]["email"].value;
var atpos=e.indexOf("@");
var dotpos=e.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=e.length)
{
alert("Not a valid e-mail address");
return false;
}
}
</script>
/*------------- Php Coding ------------------*/
<?php
if (isset($_GET['submit'])){
/* Set e-mail recipient */
$myemail = "RECIPIENT EMAIL ADDRESS";
$name = $_GET['name'];
$ct = $_GET['contact'];
$ad = $_GET['address'];
$email = $_GET['email'];
$msg = $_GET['msg'];
$from = '$name';
/* Let's prepare the message for the e-mail */
$message = "
Name: $name
Email: $email
Contact: $ct
Address: $ad
Message: $msg
";
/* Send the message using mail() function */
$m = mail($myemail,"$name", $message) or die("failed");
if ($m)
{
echo "Message Sent Successfully";
}
else
{
echo "Message Failed";
}
}
?>
/*--------------- Html Coding ------------------------*/
<form name="myForm" method="get" action="" onsubmit="return validateForm();">
<table>
<tr><td><h5>Name</h5></td><td><input type="text" name="name"/></td></tr>
<tr><td><h5>Email</h5></td><td><input type="text" name="email"/></td></tr>
<tr><td><h5>Phone</h5></td><td><input type="text" name="contact"/></td></tr>
<tr><td><h5>Address</h5></td><td><input type="text" name="address"/></td></tr>
<tr><td valign="top"><h5>Message</h5></td><td><textarea name="msg" cols="30" rows="10"/></textarea></td></tr>
<tr><td></td><td><input type="submit" name="submit" /></td></tr>
</table>
</form>
Paste this code in your contact.php page and replace the word "RECIPIENT EMAIL ADDRESS" with your email address where to receive email....