Location: PHPKode > scripts > Groone's Simple Contact Form > groones-simple-contact-form/contact/contact.php
<?php
	$abspath = "/home/user/public_html/contact/";
	
/* 
	This is groones contact form.   It's a script that allows people to put a simple contact form on their website
	It can be downloaded from http://www.groonesworld.com/
	License: GPL
	
	Thank you,  Russell H. Bennett, Jr.
*/

	include($abspath.'inc/settings.inc.php');
	
    if (!isset($_POST['mailform_from']) && empty($_POST['mailform_from'])){
		FUNCT_FORM();  //This is the contact form.  
	} else {
		if($_SERVER['REQUEST_METHOD'] == "POST"){
			FUNCT_VERIFY_REFERER($mydomain, htmlspecialchars($_SERVER['HTTP_REFERER'], ENT_QUOTES));
			FUNCT_FRM_PROCESS($_POST, $confirmmsg, $thankyou, $spammer, $company, $subject, $reciever, $mailform_url,$reply_subject);	 //This processes the contact request
		}else{
			header("Location: ".$spammer);
		}
	}
	
function FUNCT_FORM(){
?>

<div class="frmwrapper">
	<FORM METHOD="POST" ACTION="contact.php">
     <span class="reqflds">required fields *</span><br />
     <span>Name:</span> <INPUT TYPE="TEXT" NAME="first" size="37"><br />
     <span>*Email Address:</span><INPUT TYPE="TEXT" NAME="mailform_from" size="37"><br />
     <span>How did you find us?</span>
     <select size="1" name="D1">
        <option selected>Search Engine</option>
		<option>Television</option>
		<option>News Paper</option>
       	<option>Radio Ad</option>
		<option>Search Engine</option>
		<option>Friend</option>
    	<option>Other</option>
	</select><br />
    <span>Message:</span><br /><textarea rows="8" cols="36" name="myMsg"> </textarea><br />
	<INPUT TYPE="SUBMIT" VALUE="Submit">&nbsp;&nbsp;<INPUT TYPE="RESET" VALUE="Reset">
    </FORM>
</div>

<?php
}

function FUNCT_VERIFY_REFERER($mdomain, $rdomain){
	if (strpos($rdomain, $mdomain) === FALSE) {
		header("Location: ".$mdomain);
		exit();	
	}
}

function FUNCT_FRM_PROCESS($userdata, $gotIt, $tyurl, $surl, $scompany, $ssubject, $sreciever, $smailform_url,$sreply_subject){

	//We need to clean our form variables first
	$mailform_from = htmlspecialchars($userdata['mailform_from'], ENT_QUOTES);
	$mailform_form = str_replace("RCPT TO:", "", $mailform_form);
	$firstname = htmlspecialchars($userdata['first'], ENT_QUOTES);
	$heardabout =  htmlspecialchars($userdata['D1'], ENT_QUOTES);
	$contactmsg =  htmlspecialchars($userdata['myMsg'], ENT_QUOTES);
	
	$headers = "From: " . $mailform_from . "\n"; // From address
	$headers .= "Reply-To: " . $mailform_from . "\n"; // Reply-to address
	$headers .= "Organization: " . $scompany . "\n"; // Organisation
	$headers .= "Content-Type: text/html; charset=iso-8859-1\n"; // Type

	$reply_headers = "From: " . $scompany . "\n"; // From address
	$reply_headers .= "Reply-To: " . $sreciever . "\n"; // Reply-to address
	$reply_headers .= "Organization: " . $scompany . "\n"; // Organisation
	$reply_headers .= "Content-Type: text/html; charset=iso-8859-1\n"; // Type
	$chkmsg = htmlspecialchars($userdata['myMsg']);
	
	$design = FUNCT_ALERT_MSG($firstname,$mailform_from,$heardabout,$contactmsg);
		
	if (mailok($chkmsg) == "GOOD"){       
		if(ereg("^.+@.+\\..+$", $mailform_from)) {
  			mail(str_replace("RCPT TO:", "", $sreciever), str_replace("RCPT TO:", "", $ssubject), str_replace("RCPT TO:", "", $design), str_replace("RCPT TO:", "", $headers));
  			mail(str_replace("RCPT TO:", "", $mailform_from), str_replace("RCPT TO:", "", $sreply_subject), str_replace("RCPT TO:", "", $gotIt), str_replace("RCPT TO:", "", $reply_headers));

			echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
			<head>
			<title>" . $scompany . "</title>
			<META http-equiv=\"refresh\" content=\"0;URL=" . $tyurl . "\">";
			echo "<body bgcolor=\"#1f1e23\" text=\"#ffffff\" link=\"yellow\" onLoad=\"history.go(+1)\">";
    		echo '<script type="text/javascript">
  			<!--
      			alert("Thank you! Your message has been recieved.");
  			// -->
  			</script>';
			echo "</body></html>";
		}else{ 
  			echo 'Invalid email, try again'; 
		}
	}else{
		header('Location: ' . $surl );
		exit();
	}
} 
function FUNCT_ALERT_MSG($fn = '',$mf = '',$ha = '',$cm = ''){
$retval = '
<html>
<head>
<title>Your Site</title>
</head>
<body>
<div align="center"><center>
   <table  bgcolor="#000000" border="1" width="100%" cellpadding="0" cellspacing="0">
      <tr>
         <td>
            <table bgcolor="#ffffff" border="0" width="100%" cellpadding="8" cellspacing="0">
               <tr>
                  <td>
                  <FONT FACE="Arial">
                  <b>Email From:</b> <br>' . $fn . ' at email address ' . $mf . '</FONT>
                  </td>
               </tr>
               <tr>
                  <td><FONT FACE="Arial"><B>How did you hear about us?</B></FONT><BR>
                  ' .$ha. '
                  </td>
               </tr>
               <tr>
                  <td><FONT FACE="Arial"><br><b>Message:</b><br>
                        ' . $cm . '</FONT>
                  </td>
               </tr>
            </table>
         </td>
      </tr>
   </table></center></div>
   </body>
</html>';
	return $retval;
}
function mailok($usermsg) {
	global $abspath;
	include($abspath."inc/badwords.inc.php");

	$usermsg = strtoupper($usermsg);
	$tmpbad = strtoupper($badwords);
	$badwords = explode(",",$tmpbad);
	$ding = "GOOD";
	$i = 0;
	
	while (($ding == "GOOD") && ($i <= count($badwords)-1)){
		if (strpos($usermsg, $badwords[$i]) !== FALSE) {
			$ding = "BAD";	
		}
		$i++;
	}
	return $ding;
}
?>
Return current item: Groone's Simple Contact Form