Location: PHPKode > scripts > Free Contact Form > Contact/contact.php
<?
session_start();
$cansend=$HTTP_POST_VARS['cansend'];
if($cansend==1) {
require 'contact_setting.inc';
$mailTo = "$mailto";

$mailSubject="From ".$HTTP_POST_VARS["txtname"];
$name=$HTTP_POST_VARS["txtname"];
$company=$HTTP_POST_VARS["txtcompany"];
$address=$HTTP_POST_VARS["txtaddress"];
$phone=$HTTP_POST_VARS["txtphone"];
$fax=$HTTP_POST_VARS["txtfax"];
$email=$HTTP_POST_VARS["txtemail"];
$url=$HTTP_POST_VARS["txturl"];
$purpose=$HTTP_POST_VARS["txtpurpose"];
$comment=$HTTP_POST_VARS["txtcomment"];

$mailbody="Name :".$name;
$mailbody=$mailbody."\n Company :".$company;
$mailbody=$mailbody."\n Address :".$address;
$mailbody=$mailbody."\nPhone: ".$phone;
$mailbody=$mailbody."\nFax :".$fax;
$mailbody=$mailbody."\nEmail :".$email;
$mailbody=$mailbody."\nURL :".$url;
$mailbody=$mailbody."\nPurpose :".$purpose;
$mailbody=$mailbody."\nComments :".$comment;

if(1)
{
$status="<div align='center' class='highlight1' style='width: 750px;'>Thank you for contacting us. We will respond you shortly<br><br></div></center>";
}
else
{
$status="<center><br><br><br><div  class='highlight1'>Problem in sending your request.</div></center>";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Contact Form</title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
<link href="style/contact.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0" background="images/bg.jpg" style=" border-left:1px solid #7f7f7f; border-right:1px solid #7f7f7f; border-bottom:1px solid #7f7f7f; ">
  
  <tr>
    <td colspan="10"><img src="images/logo.jpg" width="179" height="80" /></td>
  </tr>
  
  <tr>
    <td colspan="2">&nbsp;</td>
    <td colspan="8">&nbsp;</td>
  </tr>

  <tr>
    <td width="2%" bgcolor="#EDEEFC" style="border-bottom:1px solid #cccccc; border-top:1px solid #cccccc">&nbsp;</td>
    <td width="14%" bgcolor="#EDEEFC" style="border-bottom:1px solid #cccccc;border-top:1px solid #cccccc"><b class="emailtxt">Contact Us </b></td>
    <td colspan="8" bgcolor="#EDEEFC" style="border-bottom:1px solid #cccccc;border-top:1px solid #cccccc">&nbsp;</td>
  </tr>
     <?php
		 if($status) {
		 ?>
		 <tr> 
                  <td colspan="6" class="highlight">&nbsp;</td>
                </tr>
                <tr> 
                  <td colspan="6" class="highlight"><?php echo $status;?></td>
                </tr>
				<tr> 
                  <td colspan="6" class="highlight1" align="center"><a href="javascript: history.go(-1)">Back</a></td>
                </tr>
                <?php
		 }
		 else {
		?>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td colspan="8">&nbsp;</td>
  </tr>
   <form method="post" name=form1 action="contact.php" onSubmit="return validate();">
  <tr>
    <td colspan="2">&nbsp;</td>
    <td width="23%" valign="top"><span class="text">Name: </span></td>
    <td colspan="7"><input name="txtname" type="text" class="text1"  style="width:250" maxlength="150" /></td>
  </tr>
  <tr>
    <td colspan="10">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td valign="top"><span class="text">Company Name: </span></td>
    <td colspan="7"><input name="txtcompany" type="text" class="text1"  style="width:250" maxlength="150" /></td>
  </tr>
  <tr>
    <td colspan="10">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td valign="top"><span class="text">Address:</span></td>
    <td colspan="7"><input name="txtaddress" type="text" class="text1"  style="width:250" maxlength="150" /></td>
  </tr>
  <tr>
    <td colspan="10">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td valign="top"><span class="text">Phone Number:</span></td>
    <td colspan="7"><input name="txtphone" type="text" class="text1"  style="width:250" maxlength="150" /></td>
  </tr>
  <tr>
    <td colspan="10">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td valign="top"><span class="text">Fax Number: </span></td>
    <td colspan="7"><input name="txtfax" type="text" class="text1"  style="width:250" maxlength="150" /></td>
  </tr>
  <tr>
    <td colspan="10">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td valign="top"><span class="text">E-mail id: </span></td>
    <td colspan="7"><input name="txtemail" type="text" class="text1"  style="width:250" maxlength="150" /></td>
  </tr>
  <tr>
    <td colspan="10">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td valign="top"><span class="text">URL: </span></td>
    <td colspan="7"><input name="txturl" type="text" class="text1"  style="width:250" maxlength="150" /></td>
  </tr>
  <tr>
    <td colspan="10">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td valign="top"><span class="text">Contact Purpose: </span></td>
    <td colspan="7"><input name="txtpurpose" type="text" class="text1"  style="width:250" maxlength="150" /></td>
  </tr>
  <tr>
    <td colspan="10">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td valign="top"><span class="text">Comment ( if any ): </span></td>
    <td colspan="7"><textarea name="txtcomment" cols="25"></textarea></td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td valign="top">&nbsp;</td>
    <td colspan="7">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td valign="top">&nbsp;</td><input type="hidden" name="cansend" value="0">
    <td width="22%"><input name="submit" type="submit" class="redbutton" value = "Submit" /></td>
    <td width="39%" colspan="6"><input name="reset" type="reset" class="redbutton" value = "Reset" /></td>
  </tr></form>
  <?php } ?> 
  <tr>
    <td colspan="2">&nbsp;</td>
    <td valign="top">&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="6">&nbsp;</td>
  </tr>
</table>
</body>
</html>
<script language="JavaScript">
function validate()
{
	if(trim(document.form1.txtname.value) == "")
	{
		alert("Please Enter Your Name");
		document.form1.txtname.focus();
		return false;
	}
	if(trim(document.form1.txtcompany.value) == "")
	{
		alert("Please Enter Your Company Name");
		document.form1.txtcompany.focus();
		return false;
	}
	if(trim(document.form1.txtaddress.value) == "")
	{
		alert("Please Enter Your Address");
		document.form1.txtaddress.focus();
		return false;
	}
		phoneno = document.form1.txtphone.value;
	len = phoneno.length;
	if(len > 0)
	{
		for(i=0;i<len;i++)
		{
			x = phoneno.substr(i,1)
			if( !( (x >= '0' && x <= '9') || x == '-') )
			{
				alert("Please Enter the valid Phone number");
				document.form1.txtphone.focus();
				return false;
			}
		}
	}
	faxno = document.form1.txtfax.value;
	len = faxno.length;
	if(len > 0)
	{
		for(i=0;i<len;i++)
		{
			x = faxno.substr(i,1)
			if( !( (x >= '0' && x <= '9') || x == '-') )
			{
				alert("Please Enter the valid fax number");
				document.form1.txtfax.focus();
				return false;
			}
		}
	}
	if(trim(document.form1.txtemail.value) == "")
	{
		alert("Please Enter Your Email Id");
		document.form1.txtemail.focus();
		return false;
	}
	if( !isEmail(document.form1.txtemail.value) )
	{
		alert("Please Enter the Valid Email Id");
		document.form1.txtemail.focus();
		document.form1.txtemail.select();
		return false;
	}
	if(trim(document.form1.txtpurpose.value) == "")
	{
		alert("Please Enter the Purpose");
		document.form1.txtpurpose.focus();
		return false;
	}

	document.form1.cansend.value=1;

	return true;
}
function isEmail(emailstr)
{
	dotchar = emailstr.indexOf(".");
	atchar = emailstr.indexOf("@");
	dotlast = emailstr.lastIndexOf(".");
	spacechar = emailstr.indexOf(" ");
	len = emailstr.length;
	if( (dotchar == -1) || (atchar == -1) || (spacechar != -1) || (dotlast < atchar) || (dotlast == len - 1) )
	{
		return false;
	}
	else
	{
		return true;
	}
}
function trim(str)
{
ch = '';
for(i=0;i<str.length;i++)
{
	cha = str.charAt(i);
	if(cha != ' ')
	{
		ch = ch + cha;
	}
}
return ch;
}
</script>
Return current item: Free Contact Form