Form Getting Spammed

I don’t want a website blacklisted for sending out spam but someone is doing that and I get this kind of junk. 4 at the same time 6:11pm

example:

purpose: quote
state: CA
age: 9
first_name: behappy
last_name: byYWAmIwbRgoMskOcT
email: razer22 at yahoo.com ( it was “@” and live link so I just took it out for the thread)
cellphone: 21400857234
wkphone: 34093459776

HTML


<form id="form" method="post" action="http://wwwsite.com/send/app.php"> 
<ul id="Form" class="container">
	<li id="lo"><a href='#' class="link"> </a>
	<div>
	   <fieldset> <br />       
<label for="What is the Quote For?">What is the Quote For?</label> &nbsp;&nbsp;
<select name="Purpose" id="Purpose" data-type="purpose" class="inputclass pageRequired" title="Your Purpose?">
<option value="" selected="selected">Select One</option>
<option value="Liability">Liability</option>
<option value="Comp-Collision">Comp/Collision</option>
</select>

......
<input name="Submit" type="submit" id="submit" value="All Done &raquo;" class="button done" /> 
    <input type="hidden" name="config" value="0"/>
    <input type="hidden" name="time" value="<?php echo time(); ?>" />
    <input type="text" name="nospam" value="" style="display:none;"/>


app.php


&lt;?php
////////////////////////////////////////////////////////////////////////////
// dB Masters' PHP FormM@iler, 
// http://www.dbmasters.net/
////////////////////////////////////////////////////////////////////////////
// General Variables
	$check_referrer="no";
	$referring_domains="http://domain.com/,http://www.domain.com/,http://subdomain.domain.com/";


// options to use if hidden field "config" has a value of 0
// recipient info
	$charset[0]="iso-8859-1";
	$tomail[0]="";
	$bcc_tomail[0]="";
	if($_POST['State']=="Arizona" OR $_POST['State']=="Georgia" OR $_POST['State']=="North Carolina"){
	$group = $_POST['Age'];
	$ar_group = array("$", ",");
	$group_checked = str_replace($ar_group, "", $group);
	if(ctype_digit($group_checked) && $group_checked &gt; 17)
	$cc_tomail[0]="";
	}
// Mail contents config
	$subject[0]="App";
	$reply_to_field[0]="Email";
	$reply_to_name[0]="FirstName";
	$required_fields[0]="Purpose,State,Age,FirstName,LastName,Email,Phone";
	$required_email_fields[0]="";
	$attachment_fields[0]="";
	$return_ip[0]="yes";
	$mail_intro[0]="Please call as soon as possible";
	$mail_fields[0]="Purpose,State,Age,FirstName,LastName,Email,Phone";
	$mail_type[0]="text";
	$mail_priority[0]="1";
// Send back to sender config
	$send_copy[0]="no";
	$send_copy_format[0]="vert_table";
	$send_copy_fields[0]="Purpose,State,Age,FirstName,LastName,Email,Phone";
	$send_copy_attachment_fields[0]="";
	$copy_subject[0]="Registration";
	$copy_intro[0]="Thanks for your inquiry, the following message has been delivered.";
	$copy_from[0]="noreply@";
	$copy_tomail_field[0]="Email";
// Result options
	$header[0]="";
	$footer[0]="";
	$error_page[0]="";
	$thanks_page[0]="";

// options to use if hidden field "config" has a value of 1
// recipient info
	$charset[1]="";
	$tomail[1]="";
	$cc_tomail[1]="";
	$bcc_tomail[1]="";
// Mail contents config
	$subject[1]="";
	$reply_to_field[1]="";
	$reply_to_name[1]="";
	$required_fields[1]="";
	$required_email_fields[1]="";
	$attachment_fields[1]="";
	$return_ip[1]="";
	$mail_intro[1]="";
	$mail_fields[1]="Purpose,State,Age,FirstName,LastName,Email,Phone";
	$mail_type[1]="";
	$mail_priority[1]="";
// Send back to sender config
	$send_copy[1]="";
	$send_copy_format[1]="";
	$send_copy_fields[1]="";
	$send_copy_attachment_fields[1]="";
	$copy_subject[1]="";
	$copy_intro[1]="";
	$copy_from[1]="";
	$copy_tomail_field[1]="";
// Result options
	$header[1]="";
	$footer[1]="";
	$error_page[1]="";
	$thanks_page[1]="";
/////////////////////////////////////////////////////////////////////////
// Don't muck around past this line unless you know what you are doing //
/////////////////////////////////////////////////////////////////////////
ob_start();
$config=$_POST["config"];
$debug=0;
$debug_text="";

// fix for Windows email server security
ini_set("sendmail_from",$tomail[$config]);

// email validation regular expression
//Old ereg expression
//$regex = "^[-a-z0-9!#$%&\\'*+/=?^_`{|}~]+(\\.[-a-z0-9!#$%&\\'*+/=?^_`{|}~]+)*@(([a-z0-9]([-a-z0-9]*[a-z0-9]+)?){1,63}\\.)+([a-z]([-a-z0-9]*[a-z0-9]+)?){2,63}$";
//New preg expression
$regex = "/^[-a-z0-9!#$%&\\'*+\\/=?^_`{|}~]+(\\.[-a-z0-9!#$%&\\'*+\\/=?^_`{|}~]+)*@(([a-z0-9]([-a-z0-9]*[a-z0-9]+)?){1,63}\\.)+([a-z]([-a-z0-9]*[a-z0-9]+)?){2,63}$/i";

//old ereg expression
//$header_injection_regex = "(\\r|\
)";
//new preg expression
$header_injection_regex = "/(\\r|\
)/";

if($header[$config]!="")
	include($header[$config]);

if($_POST["submit"] || $_POST["Submit"] || $_POST["submit_x"] || $_POST["Submit_x"])
{

////////////////////////////
// begin global functions //
////////////////////////////
// get visitor IP
	function getIP()
	{
		if(getenv(HTTP_X_FORWARDED_FOR))
			$user_ip=getenv("HTTP_X_FORWARDED_FOR");
		else
			$user_ip=getenv("REMOTE_ADDR");
		return $user_ip;
	}
// get value of given key
	function parseArray($key)
	{
		$array_value=$_POST[$key];
		$count=1;
		extract($array_value);
		foreach($array_value as $part_value)
		{
			if($count &gt; 1){$value.=", ";}
			$value.=$part_value;
			$count=$count+1;
		}
		return $value;
	}
// stripslashes and autolink url's
	function parseValue($value)
	{
		$value=preg_replace("/(http:\\/\\/+.[^\\s]+)/i",'&lt;a href="\\\\1"&gt;\\\\1&lt;/a&gt;', $value);
		return $value;
	}
// html header if used
	function htmlHeader()
	{
		$htmlHeader="&lt;!DOCTYPE HTML PUBLIC \\"-//W3C//DTD HTML 4.01//EN\\"&gt;\
&lt;html&gt;\
&lt;head&gt;&lt;meta http-equiv=\\"Content-Type\\" content=\\"text/html; charset=".$charset[$config]."\\"&gt;&lt;/head&gt;\
&lt;body&gt;\
&lt;table cellpadding=\\"2\\" cellspacing=\\"0\\" border=\\"0\\" width=\\"600\\"&gt;\
";
		return $htmlHeader;
	}
// html footer if used
	function htmlFooter()
	{
		$htmlFooter="&lt;/table&gt;\
&lt;/body&gt;\
&lt;/html&gt;\
";
		return $htmlFooter;
	}
// build verticle table format
	function buildVertTable($fields, $intro, $to, $send_ip)
	{
		$message=htmlHeader();
		if($intro != "")
			$message.="&lt;tr&gt;\
&lt;td align=\\"left\\" valign=\\"top\\" colspan=\\"2\\"&gt;".$intro."&lt;/td&gt;\
&lt;/tr&gt;\
";
		$fields_check=preg_split('/,/',$fields);
		$run=sizeof($fields_check);
		for($i=0;$i&lt;$run;$i++)
		{
			$cur_key=$fields_check[$i];
			$cur_value=$_POST[$cur_key];
			if(is_array($cur_value))
			{
				$cur_value=parseArray($cur_key);
			}
			$cur_value=parseValue($cur_value);
			if($allow_html[$config]=="no")
				$cur_value=htmlspecialchars(nl2br($cur_value));
			else
				$cur_value=nl2br($cur_value);
			$message.="&lt;tr&gt;\
&lt;td align=\\"left\\" valign=\\"top\\" style=\\"white-space:nowrap;\\"&gt;&lt;b&gt;".$cur_key."&lt;/b&gt;&lt;/td&gt;\
&lt;td align=\\"left\\" valign=\\"top\\" width=\\"100%\\"&gt;".$cur_value."&lt;/td&gt;\
&lt;/tr&gt;\
";
		}
		if($send_ip=="yes" && $to=="recipient")
		{
			$user_ip=getIP();
			$message.="&lt;tr&gt;\
&lt;td align=\\"left\\" valign=\\"top\\" style=\\"white-space:nowrap;\\"&gt;&lt;b&gt;Sender IP&lt;/b&gt;&lt;/td&gt;\
&lt;td align=\\"left\\" valign=\\"top\\" width=\\"100%\\"&gt;".$user_ip."&lt;/td&gt;\
&lt;/tr&gt;\
";
		}
		$message.=htmlFooter();
		return $message;
	}
// build horizontal table format
	function buildHorzTable($fields, $intro, $to, $send_ip)
	{
		$message=htmlHeader();
		$fields_check=preg_split('/,/',$fields);
		$run=sizeof($fields_check);
		if($intro != "")
			$message.="&lt;tr&gt;\
&lt;td align=\\"left\\" valign=\\"top\\" colspan=\\"".$run."\\"&gt;".$intro."&lt;/td&gt;\
&lt;/tr&gt;\
";
		$message.="&lt;tr&gt;\
";
		for($i=0;$i&lt;$run;$i++)
		{
			$cur_key=$fields_check[$i];
			$message.="&lt;td align=\\"left\\" valign=\\"top\\" style=\\"white-space:nowrap;\\"&gt;&lt;b&gt;".$cur_key."&lt;/b&gt;&lt;/td&gt;\
";
		}
		if($send_ip=="yes" && $to=="recipient")
			$message.="&lt;td align=\\"left\\" valign=\\"top\\" style=\\"white-space:nowrap;\\"&gt;&lt;b&gt;Sender IP&lt;/b&gt;&lt;/td&gt;\
";
		$message.="&lt;/tr&gt;\
";
		$message.="&lt;tr&gt;\
";
		for($i=0;$i&lt;$run;$i++)
		{
			$cur_key=$fields_check[$i];
			$cur_value=$_POST[$cur_key];
			if(is_array($cur_value))
			{
				$cur_value=parseArray($cur_key);
			}
			$cur_value=parseValue($cur_value);
			if($allow_html[$config]=="no")
				$cur_value=htmlspecialchars(nl2br($cur_value));
			else
				$cur_value=nl2br($cur_value);
			$message.="&lt;td align=\\"left\\" valign=\\"top\\"&gt;".$cur_value."&lt;/td&gt;\
";
		}
		$message.="&lt;/tr&gt;\
";
		$message.="&lt;tr&gt;\
";
		if($send_ip=="yes" && $to=="recipient")
		{
			$user_ip=getIP();
			$message.="&lt;td align=\\"left\\" valign=\\"top\\"&gt;".$user_ip."&lt;/td&gt;\
";
		}
		$message.="&lt;/tr&gt;\
";
		$message.=htmlFooter();
		return $message;
	}
// build plain text format
	function buildTextTable($fields, $intro, $to, $send_ip)
	{
		$message="";
		if($intro != "")
			$message.=$intro."\
\
";
		$fields_check=preg_split('/,/',$fields);
		$run=sizeof($fields_check);
		for($i=0;$i&lt;$run;$i++)
		{
			$cur_key=$fields_check[$i];
			$cur_value=$_POST[$cur_key];
			if(is_array($cur_value))
			{
				$cur_value=parseArray($cur_key);
			}
			$cur_value=parseValue($cur_value);
			if($allow_html[$config]=="no")
				$cur_value=htmlspecialchars($cur_value);
			else
				$cur_value=$cur_value;
			$message.="".$cur_key.": ".$cur_value."\
";
		}
		if($send_ip=="yes" && $to=="recipient")
		{
			$user_ip=getIP();
			$message.="Sender IP: ".$user_ip."\
";
		}
		return $message;
	}
// get the proper build fonction
	function buildTable($format, $fields, $intro, $to, $send_ip)
	{
		if($format=="vert_table")
			$message=buildVertTable($fields, $intro, $to, $send_ip);
		else if($format=="horz_table")
			$message=buildHorzTable($fields, $intro, $to, $send_ip);
		else
			$message=buildTextTable($fields, $intro, $to, $send_ip);
		return $message;
	}
// referrer checking security option
	function checkReferer()
	{
		if($check_referrer=="yes")
		{
			$ref_check=preg_split('/,/',$referring_domains);
			$ref_run=sizeof($ref_check);
			$referer=$_SERVER['HTTP_REFERER'];
			$domain_chk="no";
			for($i=0;$i&lt;$ref_run;$i++)
			{
				$cur_domain=$ref_check[$i];
				if(stristr($referer,$cur_domain)){$domain_chk="yes";}
			}
		}
		else
		{
			$domain_chk="yes";
		}
		return $domain_chk;
	}
// checking required fields and email fields
	function checkFields($text_fields, $email_fields, $regex)
	{
      	$error_message="";
		if($debug==1)
			$error_message.="&lt;li&gt;text_fields: ".$text_fields."&lt;br /&gt;email_fields: ".$email_fields."&lt;br /&gt;reply_to_field: ".$reply_to_field."&lt;br /&gt;reply_to_name: ".reply_to_name."&lt;/li&gt;";
		if($text_fields != "")
		{
			$req_check=preg_split('/,/',$text_fields);
			$req_run=sizeof($req_check);
			for($i=0;$i&lt;$req_run;$i++)
			{
				$cur_field_name=$req_check[$i];
				$cur_field=$_POST[$cur_field_name];
				if($cur_field=="")
				{
					$error_message.="&lt;li&gt;You are missing the &lt;b&gt;".$req_check[$i]."&lt;/b&gt; field&lt;/li&gt;\
";
				}
			}
		}
		if($email_fields != "")
		{
			$email_check=preg_split('/,/',$email_fields);
			$email_run=sizeof($email_check);
			for($i=0;$i&lt;$email_run;$i++)
			{
				$cur_email_name=$email_check[$i];
				$cur_email=$_POST[$cur_email_name];
				//if($cur_email=="" || !eregi($regex, $cur_email))
				if($cur_email=="" || !preg_match($regex, $cur_email))
				{
					$error_message.="&lt;li&gt;You are missing the &lt;b&gt;".$email_check[$i]."&lt;/b&gt; field or it is not a valid email address.&lt;/li&gt;\
";
				}
			}
		}
		return $error_message;
	}
// attachment function
	function getAttachments($attachment_fields, $message, $content_type, $border)
	{
		$att_message="This is a multi-part message in MIME format.\\r\
";
		$att_message.="--{$border}\\r\
";
		$att_message.=$content_type."\\r\
";
		$att_message.="Content-Transfer-Encoding: 7bit\\r\
\\r\
";
		$att_message.=$message."\\r\
\\r\
";

		$att_check=preg_split('/,/',$attachment_fields);
		$att_run=sizeof($att_check);
		for($i=0;$i&lt;$att_run;$i++)
		{
			$fileatt=$_FILES[$att_check[$i]]['tmp_name'];
			$fileatt_name=$_FILES[$att_check[$i]]['name'];
			$fileatt_type=$_FILES[$att_check[$i]]['type'];
			if (is_uploaded_file($fileatt))
			{
				$file=fopen($fileatt,'rb');
				$data=fread($file,filesize($fileatt));
				fclose($file);
				$data=chunk_split(base64_encode($data));
				$att_message.="--{$border}\
";
				$att_message.="Content-Type: {$fileatt_type}; name=\\"{$fileatt_name}\\"\\r\
";
				$att_message.="Content-Disposition: attachment; filename=\\"{$fileatt_name}\\"\\r\
";
				$att_message.="Content-Transfer-Encoding: base64\\r\
\\r\
".$data."\\r\
\\r\
";
			}
		}
		$att_message.="--{$border}--\
";
		return $att_message;
	}
// function to set content type
	function contentType($charset, $format)
	{
		if($format=="vert_table")
			$content_type="Content-type: text/html; charset=".$charset."\\r\
";
		else if($format=="horz_table")
			$content_type="Content-type: text/html; charset=".$charset."\\r\
";
		else
			$content_type="Content-type: text/plain; charset=".$charset."\\r\
";
		return $content_type;
	}
//////////////////////////
// end global functions //
//////////////////////////

////////////////////////////////
// begin procedural scripting //
////////////////////////////////
	// anti-spam empty field check
	if($_POST[$empty_field[$config]] != "")
	{
		$empty_message = "&lt;li&gt;This submission failed and was flagged as spam.&lt;/li&gt;\
";
	}
	// anti-spam character scan check
	if(strlen($character_scan[$config]) &gt; 0)
	{
		$spam_message="";
		$field_check=preg_split('/,/',$character_scan[$config]);
		$field_run=sizeof($field_check);
		for($i=0;$i&lt;$field_run;$i++)
		{
			$cur_field_name=$field_check[$i];
			$cur_field=$_POST[$cur_field_name];
			if(preg_match("/&lt;(.|\
)+?&gt;/", $cur_field) || preg_match("/\\[(.|\
)+?\\]/", $cur_field))
				$spam_message.="&lt;li&gt;This message contains disallowed characters.&lt;/li&gt;\
";
		}
	}
	// anti-spam time delay check
	if((strlen($time_delay[$config]) &gt; 0 && strlen($_POST["time"]) &gt; 0) || (strlen($time_delay[$config]) &gt; 0 && (strlen($_POST["time"]) == 0 || !$_POST["time"])))
	{
		if((time() - $_POST["time"]) &lt; $time_delay[$config])
			$time_message = "&lt;li&gt;This has been stopped by the timer, and is likely spam.&lt;/li&gt;\
";
	}
	// anti-spam CAPTCHA check
	if(strlen($captcha_codes[$config]) &gt; 0)
	{
		$captcha_check=preg_split('/,/',$captcha_codes[$config]);
		if(strtolower($_POST["captcha_entry"]) != strtolower($captcha_check[$_POST["captcha_code"]]))
			$captcha_message = "&lt;li&gt;CAPTCHA test did not match.&lt;/li&gt;\
";
	}
	// anti-spam max URL check
	if(strlen($max_url_fields[$config]) &gt; 0)
	{
		$max_url_message="";
		$field_check=preg_split('/,/',$max_url_fields[$config]);
		$field_run=sizeof($field_check);
		for($i=0;$i&lt;$field_run;$i++)
		{
			$cur_field_name=$field_check[$i];
			$cur_field=$_POST[$cur_field_name];
			preg_match_all("/http:/", $cur_field, $matches);
			if(count($matches[0]) &gt; $max_urls[$config])
				$max_url_message.="&lt;li&gt;This message contains too many URL's.&lt;/li&gt;\
";
		}
	}
	// set anti-spam flagging option
	if(strlen($empty_message.$spam_message.$time_message.$captcha_message.$max_url_message) &gt; 0 && strlen($flag_spam[$config]) == 0)
		$set_flag = 2;
	else if(strlen($empty_message.$spam_message.$time_message.$captcha_message.$max_url_message) &gt; 0 && strlen($flag_spam[$config]) &gt; 0)
		$set_flag = 1;
	else
		$set_flag = 0;
	// header injection check
   	$security_filter="";
	if(strlen($_POST[$reply_to_field[$config]]) &gt; 0)
	{
		//if(eregi($header_injection_regex,$_POST[$reply_to_field[$config]]))
		if(preg_match($header_injection_regex,$_POST[$reply_to_field[$config]]))
			$security_filter.="&lt;li&gt;Header injection attempt detected, mail aborted.&lt;/li&gt;\
";
		else
			$reply_to_field_checked=$_POST[$reply_to_field[$config]];
	}
	if(strlen($_POST[$reply_to_name[$config]]) &gt; 0)
	{
		//if(eregi($header_injection_regex,$_POST[$reply_to_name[$config]]))
		if(preg_match($header_injection_regex,$_POST[$reply_to_name[$config]]))
			$security_filter.="&lt;li&gt;Header injection attempt detected, mail aborted.&lt;/li&gt;\
";
		else
			$reply_to_name_checked=$_POST[$reply_to_name[$config]];
	}
	// check domain referrer and continue
	$domain_chk=checkReferer();
	if($domain_chk=="yes")
	{
		$error_message=checkFields($required_fields[$config], $required_email_fields[$config], $regex);
		if(strlen($error_message) &lt; 1 && strlen($security_filter) &lt; 1 && $set_flag &lt; 2)
		{
			// build appropriate message format for recipient
			$content_type=contentType($charset[$config], $mail_type[$config]);
			$message=buildTable($mail_type[$config], $mail_fields[$config], $mail_intro[$config], "recipient", $return_ip[$config]);
			// build header data for recipient message
			//$extra="From: ".$_POST[$reply_to_field[$config]]."\\r\
";
			$extra="From: ".$reply_to_name_checked." &lt;".$reply_to_field_checked."&gt;\\r\
";
			if($cc_tomail[$config]!="")
				$extra.="Cc: ".$cc_tomail[$config]."\\r\
";
			if($bcc_tomail[$config]!="")
				$extra.="Bcc: ".$bcc_tomail[$config]."\\r\
";
			if($mail_priority[$config]!="")
				$extra.="X-Priority: ".$mail_priority[$config]."\\r\
";
			// get attachments if necessary
			if($attachment_fields[$config]!="")
			{
				$semi_rand=md5(time());
				$border="==Multipart_Boundary_x{$semi_rand}x";
				$extra.="MIME-Version: 1.0\\r\
";
				$extra.="Content-Type: multipart/mixed; boundary=\\"{$border}\\"";
				$message=getAttachments($attachment_fields[$config], $message, $content_type, $border);
			}
			else
			{
				$extra.="MIME-Version: 1.0\\r\
".$content_type;
			}
			// send recipient email
			if($debug==1)
			{
				if($set_flag == 1)
					$debug_text.="&lt;p&gt;&lt;b&gt;Mail would have sent flagged for spam if not in debug mode.&lt;/b&gt;&lt;/p&gt;";
				else
					$debug_text.="&lt;p&gt;&lt;b&gt;Mail would have sent if not in debug mode.&lt;/b&gt;&lt;/p&gt;";
			}
			else if($debug==0)
			{
				if($set_flag == 1)
					$subject = $flag_spam[$config]." ".$subject[$config];
				else
					$subject = $subject[$config];
				mail("".$tomail[$config]."", "".stripslashes($subject)."", "".stripslashes($message)."", "".$extra."");
			}
			// autoresponse email if necessary
			if($send_copy[$config]=="yes")
			{
				// build appropriate message format for autoresponse
				$content_type=contentType($charset[$config], $copy_format[$config]);
				$message=buildTable($copy_format[$config], $copy_fields[$config], $copy_intro[$config], "autoresponder", $return_ip[$config]);
				// build header data for autoresponse
				$copy_tomail=$_POST[$copy_tomail_field[$config]];
				$copy_extra="From: ".$copy_from[$config]."\\r\
";
				// get autoresponse  attachments if necessary
				if($copy_attachment_fields[$config]!="")
				{
					$semi_rand=md5(time());
					$border="==Multipart_Boundary_x{$semi_rand}x";
					$copy_extra.="MIME-Version: 1.0\\r\
";
					$copy_extra.="Content-Type: multipart/mixed; boundary=\\"{$border}\\"";
					$message=getAttachments($copy_attachment_fields[$config], $message, $content_type, $border);
				}
				else
				{
					$copy_extra.="MIME-Version: 1.0\\r\
".$content_type;
				}
				// send autoresponse email
				if($debug==1)
				{
					if($set_flag == 1)
						$debug_text.="&lt;p&gt;&lt;b&gt;Autoresponder would have sent flagged for spam if not in debug mode.&lt;/b&gt;&lt;/p&gt;";
					else
						$debug_text.="&lt;p&gt;&lt;b&gt;Autoresponder would have sent if not in debug mode.&lt;/b&gt;&lt;/p&gt;";
				}
				else if($debug==0)
				{
					$send_copy = 1;
					//if($copy_tomail=="" || !eregi($regex,$copy_tomail))
					if($copy_tomail=="" || !preg_match($regex,$copy_tomail))
						$send_copy = 0;
					if($send_copy == 1)
					{
						if($set_flag == 1)
							$copy_subject = $flag_spam[$config]." ".$copy_subject[$config];
						else
							$copy_subject = $copy_subject[$config];
						mail("$copy_tomail", "".$copy_subject."", "$message", "$copy_extra");
					}
				}
			}
			// showing thanks pages from a successful submission
			if($thanks_page[$config]=="")
			{
				echo "&lt;h3&gt;".$thanks_page_title[$config]."&lt;/h3&gt;\
";
				echo "&lt;p&gt;".$thanks_page_text[$config]."&lt;/p&gt;\
";
				if(strlen($debug_text) &gt; 0)
					echo "&lt;p&gt;&lt;b&gt;&lt;i&gt;".$debug_text."&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;\
";
			}
			else
			{
				header("Location: ".$thanks_page[$config]);
			}
		}
		else
		{
			// entering error page options from missing required fields
			if($error_page[$config]=="")
			{
				echo "&lt;h3&gt;".$error_page_title[$config]."&lt;/h3&gt;\
";
				echo "&lt;ul&gt;\
";
				echo $security_filter.$empty_message.$error_message.$spam_message.$time_message.$captcha_message.$max_url_message;
				echo "&lt;/ul&gt;\
";
				echo "&lt;p&gt;".$error_page_text[$config]."&lt;/p&gt;\
";
			}
			else
			{
				header("Location: ".$error_page[$config]);
			}
		}
	}
	else
	{
		echo "&lt;h3&gt;".$error_page_title[$config]."&lt;/h3&gt;\
";
		// message if unauthorized domain trigger from referer checking option
		echo "&lt;p&gt;Sorry, mailing request came from an unauthorized domain.&lt;/p&gt;\
";
	}
//////////////////////////////
// end procedural scripting //
//////////////////////////////
}
else
{
	echo "&lt;h3&gt;Error&lt;/h3&gt;";
	echo "&lt;p&gt;No form data has been sent to the script&lt;/p&gt;\
";
}
if($footer[$config]!="")
	include($footer[$config]);
ob_end_flush();
?&gt;


I am not a php programmer so that is part of the reason it gets spammed.

How would you an expert, handle this if you wanted to make sure the data being input is sanitized, filtered, it secure from injection headers and illegal sending, email and phone are validated (without javascript) , and NO captchas whatsoever? ( I already know there are captcha solvers out there anyway and I just don’t want it.)

The form is 7 years old and I have seen tectite but I get too confused with it configuring it. So, for an eternal php newbie, iIs there a way to make this php code stronger and more secure? Please share your solutions. getting spam is like getting the finger every day you drive.

Thanks

what’s wrong with having a captcha? lol it’ll keep bots from filling out your form.

I’ll have to post about confirming the fields when I get home.

I’d say use honey pot. Captchas are just plain bad for websites. Captchas can be hacked really easily. If you don’t believe me, check this http://arstechnica.com/security/2012/05/google-recaptcha-brought-to-its-knees/

Three regular guys who know nothing about hacking broke Google’s ReCaptcha. Now if you take that to consideration, you don’t know what more people can do on your site by messing around with captchas. There are also more articles out there explaining how much revenue you can potentially lose by having captchas and recaptchas on your site. People don’t want to have to sit there and try to decipher words that are hard to see and getting an error every time it’s close to what the picture looks like. Your customers will leave and never come back because of the captcha that is in their way.

How honey pot works, honey pot uses both PHP and HTML. Honey pot checks to see if the customer has inputted anything in the hidden field. If they did input something in the hidden field, then don’t process anything they input and give them an error such as “Hello, sorry but it seems that you have inputted something that has detected you as a bot. You will now be redirected.”
This field will be hidden from a real person using HTML’s display: none;.

If you know how a spam/register bot works, they will see a page as an empty blank page with forms and fields on them. They will fill out every single field that’s on the page. Regardless of how your website looks or if it uses JQuery, bots will go through them. So since you have put the hidden field’s class as display: none;, to the bots the hidden field will show up. To a human, the field will not show unless they don’t have CSS supported on their browser.

Here is a code you can test out if you still aren’t convinced.

HTML Part

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
.honeypot {
	display: none;
}
</style>
</head>

<body>
<form action="go.php" method="POST">
<div class="honeypot"><input type="text" name="honeypot" placeholder="If you are a human, please skip this field."><br /></div>
<input type="text" name="name"><br />
<textarea name="textarea"></textarea><br />
<input type="submit" value="Submit">
</form>
</body>
</html>

PHP Part

<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {

	if(empty($_POST['honeypot'])) {

		// Process your code.
		echo $_POST['name'] . "<br />";
		echo $_POST['textarea'] . "<br />";

	} else {

		// Don't process your code, deny the client from processing what they have inputed.
		echo "Hello, sorry but it seems that you have inputted something that has detected you as a bot. You will now be redirected.";	

	}

}
?>

Another method would be to time how long it takes for the user to fill out the form and submit it, if they’ve taken less then a certain time then give a generic error message

Sounds great , I will try this.I was using just the display:none with CSS and not the actual code. You know where I should put the php part within the code above?

Is there another measure for checking the amount of numbers in a field? there had 2, when it should have been between 6 and 8 numbers with possible commas. I guess it could be text too. well, I prefer numbers, that are then transformed into a dollar amount and prefaced with a dollar sign.
checking phone # validity ( their input had 11 numbers)
checking email ( a toughie but maybe worth the effort)

I was looking into this one - http://code.tutsplus.com/tutorials/sanitize-and-validate-data-with-php-filters--net-2595

Well, if you’re unsure about the format of the string entered by the user, you could check only the lenght of the string.

if (strlen($string) <= 2) {
  // you're a bot!
}

The PHP part of the script (if you mean the one in “quote” posted by therockers) should be in a file named go.php. The HTML is calling “go.php”, it’s defined in the “action” parameter.

The code is not complete, you’ll need to add a redirect like this:

header( 'Location: http://www.yoursite.com/sorry_bot_detected.html' ) ;
exit();

instead of

echo "Hello, sorry but it seems that you have inputted something that has detected you as a bot. You will now be redirected.";	

OR add a “die();” after the line that says that the user will be redirected. Just change the message (the user won’t be redirected if you leave the code like this).

For phone numbers, I would remove all characters and check only the numbers to see if the lenght is OK. Like… you don’t want to prevent somebody to enter (555) 555-5555 for example, etc.
Or, you could use a JQuery mask directly on the field.

When this goes live, I would give the div, hidden field, class names that don’t give away the purpose (i.e. not “honeypot”). And I wouldn’t redirect the bots to a page saying “I got you, you’re a bot, and I know because you did this and that!!”.
Bots are getting smarter, and why give away any clues.

Well yeah. We all know that. This is just a test example for the OP to understand there are other ways of rejecting bots.

You can actually put it any where you want. You just have to specify in the action in your form. You can have something like

<form action="" method="POST">

And have the entire PHP code inside the same file and it will still work. If you put it at the very top of the file, still works. If you put it at the way bottom, it’ll still work. You just need to define where the action is. You can also use the global server settings.

<form action="<?php echo $_SERVER['SERVER_NAME']; ?><?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">

If you do this the URL will end up being “sitepoint.com/forums/showthread.php?1202596-Form-Getting-Spammed”. If you have a secure URL, you might want to put the https in front of the global server settings.

it’s an html extension.

If I put it in the html document, it is not formatted right and I don’t know where to put it in the php script itself.

I just got 3,461 spam emails in my box from some idiot using my form with the current script so whatever anti–spam measures the current script has are not effective.

where should I put the honeypot script into the app.php form in the first post?

Thanks

UPDATE: OK, now it is another site too where I use the same form. I really, really need a good form. Please help me out. Thanks

Change the document file to .php, all PHP functions will not work in HTML documents. You can put the PHP code in your “app.php” file if that’s where the original processed information was. I haven’t tested this because I don’t know what your information is, but don’t give it to me. Just test it yourself.

HTML

<form id="form" method="post" action="http://wwwsite.com/send/app.php"> 
<ul id="Form" class="container">
	<li id="lo"><a href='#' class="link"> </a>
	<div>
	   <fieldset> <br />       
<label for="What is the Quote For?">What is the Quote For?</label> &nbsp;&nbsp;
<select name="Purpose" id="Purpose" data-type="purpose" class="inputclass pageRequired" title="Your Purpose?">
<option value="" selected="selected">Select One</option>
<option value="Liability">Liability</option>
<option value="Comp-Collision">Comp/Collision</option>
</select>

......
<input name="Submit" type="submit" id="submit" value="All Done &raquo;" class="button done" /> 
    <input type="hidden" name="config" value="0"/>
    <input type="hidden" name="time" value="<?php echo time(); ?>" />
    <div style="display: none;"><input type="hidden" name="mlpw9" placeholder="If you are a human, ignore this field."></div>
    <input type="text" name="nospam" value="" style="display:none;"/>

PHP

&lt;?php
if($_SERVER['REQUEST_METHOD'] == "POST") {

	if(empty($_POST['mlpw9'])) {

////////////////////////////////////////////////////////////////////////////
// dB Masters' PHP FormM@iler, 
// http://www.dbmasters.net/
////////////////////////////////////////////////////////////////////////////
// General Variables
	$check_referrer="no";
	$referring_domains="http://domain.com/,http://www.domain.com/,http://subdomain.domain.com/";


// options to use if hidden field "config" has a value of 0
// recipient info
	$charset[0]="iso-8859-1";
	$tomail[0]="";
	$bcc_tomail[0]="";
	if($_POST['State']=="Arizona" OR $_POST['State']=="Georgia" OR $_POST['State']=="North Carolina"){
	$group = $_POST['Age'];
	$ar_group = array("$", ",");
	$group_checked = str_replace($ar_group, "", $group);
	if(ctype_digit($group_checked) && $group_checked &gt; 17)
	$cc_tomail[0]="";
	}
// Mail contents config
	$subject[0]="App";
	$reply_to_field[0]="Email";
	$reply_to_name[0]="FirstName";
	$required_fields[0]="Purpose,State,Age,FirstName,LastName,Email,Phone";
	$required_email_fields[0]="";
	$attachment_fields[0]="";
	$return_ip[0]="yes";
	$mail_intro[0]="Please call as soon as possible";
	$mail_fields[0]="Purpose,State,Age,FirstName,LastName,Email,Phone";
	$mail_type[0]="text";
	$mail_priority[0]="1";
// Send back to sender config
	$send_copy[0]="no";
	$send_copy_format[0]="vert_table";
	$send_copy_fields[0]="Purpose,State,Age,FirstName,LastName,Email,Phone";
	$send_copy_attachment_fields[0]="";
	$copy_subject[0]="Registration";
	$copy_intro[0]="Thanks for your inquiry, the following message has been delivered.";
	$copy_from[0]="noreply@";
	$copy_tomail_field[0]="Email";
// Result options
	$header[0]="";
	$footer[0]="";
	$error_page[0]="";
	$thanks_page[0]="";

// options to use if hidden field "config" has a value of 1
// recipient info
	$charset[1]="";
	$tomail[1]="";
	$cc_tomail[1]="";
	$bcc_tomail[1]="";
// Mail contents config
	$subject[1]="";
	$reply_to_field[1]="";
	$reply_to_name[1]="";
	$required_fields[1]="";
	$required_email_fields[1]="";
	$attachment_fields[1]="";
	$return_ip[1]="";
	$mail_intro[1]="";
	$mail_fields[1]="Purpose,State,Age,FirstName,LastName,Email,Phone";
	$mail_type[1]="";
	$mail_priority[1]="";
// Send back to sender config
	$send_copy[1]="";
	$send_copy_format[1]="";
	$send_copy_fields[1]="";
	$send_copy_attachment_fields[1]="";
	$copy_subject[1]="";
	$copy_intro[1]="";
	$copy_from[1]="";
	$copy_tomail_field[1]="";
// Result options
	$header[1]="";
	$footer[1]="";
	$error_page[1]="";
	$thanks_page[1]="";
/////////////////////////////////////////////////////////////////////////
// Don't muck around past this line unless you know what you are doing //
/////////////////////////////////////////////////////////////////////////
ob_start();
$config=$_POST["config"];
$debug=0;
$debug_text="";

// fix for Windows email server security
ini_set("sendmail_from",$tomail[$config]);

// email validation regular expression
//Old ereg expression
//$regex = "^[-a-z0-9!#$%&\\'*+/=?^_`{|}~]+(\\.[-a-z0-9!#$%&\\'*+/=?^_`{|}~]+)*@(([a-z0-9]([-a-z0-9]*[a-z0-9]+)?){1,63}\\.)+([a-z]([-a-z0-9]*[a-z0-9]+)?){2,63}$";
//New preg expression
$regex = "/^[-a-z0-9!#$%&\\'*+\\/=?^_`{|}~]+(\\.[-a-z0-9!#$%&\\'*+\\/=?^_`{|}~]+)*@(([a-z0-9]([-a-z0-9]*[a-z0-9]+)?){1,63}\\.)+([a-z]([-a-z0-9]*[a-z0-9]+)?){2,63}$/i";

//old ereg expression
//$header_injection_regex = "(\\r|\
)";
//new preg expression
$header_injection_regex = "/(\\r|\
)/";

if($header[$config]!="")
	include($header[$config]);

if($_POST["submit"] || $_POST["Submit"] || $_POST["submit_x"] || $_POST["Submit_x"])
{

////////////////////////////
// begin global functions //
////////////////////////////
// get visitor IP
	function getIP()
	{
		if(getenv(HTTP_X_FORWARDED_FOR))
			$user_ip=getenv("HTTP_X_FORWARDED_FOR");
		else
			$user_ip=getenv("REMOTE_ADDR");
		return $user_ip;
	}
// get value of given key
	function parseArray($key)
	{
		$array_value=$_POST[$key];
		$count=1;
		extract($array_value);
		foreach($array_value as $part_value)
		{
			if($count &gt; 1){$value.=", ";}
			$value.=$part_value;
			$count=$count+1;
		}
		return $value;
	}
// stripslashes and autolink url's
	function parseValue($value)
	{
		$value=preg_replace("/(http:\\/\\/+.[^\\s]+)/i",'&lt;a href="\\\\1"&gt;\\\\1&lt;/a&gt;', $value);
		return $value;
	}
// html header if used
	function htmlHeader()
	{
		$htmlHeader="&lt;!DOCTYPE HTML PUBLIC \\"-//W3C//DTD HTML 4.01//EN\\"&gt;\
&lt;html&gt;\
&lt;head&gt;&lt;meta http-equiv=\\"Content-Type\\" content=\\"text/html; charset=".$charset[$config]."\\"&gt;&lt;/head&gt;\
&lt;body&gt;\
&lt;table cellpadding=\\"2\\" cellspacing=\\"0\\" border=\\"0\\" width=\\"600\\"&gt;\
";
		return $htmlHeader;
	}
// html footer if used
	function htmlFooter()
	{
		$htmlFooter="&lt;/table&gt;\
&lt;/body&gt;\
&lt;/html&gt;\
";
		return $htmlFooter;
	}
// build verticle table format
	function buildVertTable($fields, $intro, $to, $send_ip)
	{
		$message=htmlHeader();
		if($intro != "")
			$message.="&lt;tr&gt;\
&lt;td align=\\"left\\" valign=\\"top\\" colspan=\\"2\\"&gt;".$intro."&lt;/td&gt;\
&lt;/tr&gt;\
";
		$fields_check=preg_split('/,/',$fields);
		$run=sizeof($fields_check);
		for($i=0;$i&lt;$run;$i++)
		{
			$cur_key=$fields_check[$i];
			$cur_value=$_POST[$cur_key];
			if(is_array($cur_value))
			{
				$cur_value=parseArray($cur_key);
			}
			$cur_value=parseValue($cur_value);
			if($allow_html[$config]=="no")
				$cur_value=htmlspecialchars(nl2br($cur_value));
			else
				$cur_value=nl2br($cur_value);
			$message.="&lt;tr&gt;\
&lt;td align=\\"left\\" valign=\\"top\\" style=\\"white-space:nowrap;\\"&gt;&lt;b&gt;".$cur_key."&lt;/b&gt;&lt;/td&gt;\
&lt;td align=\\"left\\" valign=\\"top\\" width=\\"100%\\"&gt;".$cur_value."&lt;/td&gt;\
&lt;/tr&gt;\
";
		}
		if($send_ip=="yes" && $to=="recipient")
		{
			$user_ip=getIP();
			$message.="&lt;tr&gt;\
&lt;td align=\\"left\\" valign=\\"top\\" style=\\"white-space:nowrap;\\"&gt;&lt;b&gt;Sender IP&lt;/b&gt;&lt;/td&gt;\
&lt;td align=\\"left\\" valign=\\"top\\" width=\\"100%\\"&gt;".$user_ip."&lt;/td&gt;\
&lt;/tr&gt;\
";
		}
		$message.=htmlFooter();
		return $message;
	}
// build horizontal table format
	function buildHorzTable($fields, $intro, $to, $send_ip)
	{
		$message=htmlHeader();
		$fields_check=preg_split('/,/',$fields);
		$run=sizeof($fields_check);
		if($intro != "")
			$message.="&lt;tr&gt;\
&lt;td align=\\"left\\" valign=\\"top\\" colspan=\\"".$run."\\"&gt;".$intro."&lt;/td&gt;\
&lt;/tr&gt;\
";
		$message.="&lt;tr&gt;\
";
		for($i=0;$i&lt;$run;$i++)
		{
			$cur_key=$fields_check[$i];
			$message.="&lt;td align=\\"left\\" valign=\\"top\\" style=\\"white-space:nowrap;\\"&gt;&lt;b&gt;".$cur_key."&lt;/b&gt;&lt;/td&gt;\
";
		}
		if($send_ip=="yes" && $to=="recipient")
			$message.="&lt;td align=\\"left\\" valign=\\"top\\" style=\\"white-space:nowrap;\\"&gt;&lt;b&gt;Sender IP&lt;/b&gt;&lt;/td&gt;\
";
		$message.="&lt;/tr&gt;\
";
		$message.="&lt;tr&gt;\
";
		for($i=0;$i&lt;$run;$i++)
		{
			$cur_key=$fields_check[$i];
			$cur_value=$_POST[$cur_key];
			if(is_array($cur_value))
			{
				$cur_value=parseArray($cur_key);
			}
			$cur_value=parseValue($cur_value);
			if($allow_html[$config]=="no")
				$cur_value=htmlspecialchars(nl2br($cur_value));
			else
				$cur_value=nl2br($cur_value);
			$message.="&lt;td align=\\"left\\" valign=\\"top\\"&gt;".$cur_value."&lt;/td&gt;\
";
		}
		$message.="&lt;/tr&gt;\
";
		$message.="&lt;tr&gt;\
";
		if($send_ip=="yes" && $to=="recipient")
		{
			$user_ip=getIP();
			$message.="&lt;td align=\\"left\\" valign=\\"top\\"&gt;".$user_ip."&lt;/td&gt;\
";
		}
		$message.="&lt;/tr&gt;\
";
		$message.=htmlFooter();
		return $message;
	}
// build plain text format
	function buildTextTable($fields, $intro, $to, $send_ip)
	{
		$message="";
		if($intro != "")
			$message.=$intro."\
\
";
		$fields_check=preg_split('/,/',$fields);
		$run=sizeof($fields_check);
		for($i=0;$i&lt;$run;$i++)
		{
			$cur_key=$fields_check[$i];
			$cur_value=$_POST[$cur_key];
			if(is_array($cur_value))
			{
				$cur_value=parseArray($cur_key);
			}
			$cur_value=parseValue($cur_value);
			if($allow_html[$config]=="no")
				$cur_value=htmlspecialchars($cur_value);
			else
				$cur_value=$cur_value;
			$message.="".$cur_key.": ".$cur_value."\
";
		}
		if($send_ip=="yes" && $to=="recipient")
		{
			$user_ip=getIP();
			$message.="Sender IP: ".$user_ip."\
";
		}
		return $message;
	}
// get the proper build fonction
	function buildTable($format, $fields, $intro, $to, $send_ip)
	{
		if($format=="vert_table")
			$message=buildVertTable($fields, $intro, $to, $send_ip);
		else if($format=="horz_table")
			$message=buildHorzTable($fields, $intro, $to, $send_ip);
		else
			$message=buildTextTable($fields, $intro, $to, $send_ip);
		return $message;
	}
// referrer checking security option
	function checkReferer()
	{
		if($check_referrer=="yes")
		{
			$ref_check=preg_split('/,/',$referring_domains);
			$ref_run=sizeof($ref_check);
			$referer=$_SERVER['HTTP_REFERER'];
			$domain_chk="no";
			for($i=0;$i&lt;$ref_run;$i++)
			{
				$cur_domain=$ref_check[$i];
				if(stristr($referer,$cur_domain)){$domain_chk="yes";}
			}
		}
		else
		{
			$domain_chk="yes";
		}
		return $domain_chk;
	}
// checking required fields and email fields
	function checkFields($text_fields, $email_fields, $regex)
	{
  	$error_message="";
		if($debug==1)
			$error_message.="&lt;li&gt;text_fields: ".$text_fields."&lt;br /&gt;email_fields: ".$email_fields."&lt;br /&gt;reply_to_field: ".$reply_to_field."&lt;br /&gt;reply_to_name: ".reply_to_name."&lt;/li&gt;";
		if($text_fields != "")
		{
			$req_check=preg_split('/,/',$text_fields);
			$req_run=sizeof($req_check);
			for($i=0;$i&lt;$req_run;$i++)
			{
				$cur_field_name=$req_check[$i];
				$cur_field=$_POST[$cur_field_name];
				if($cur_field=="")
				{
					$error_message.="&lt;li&gt;You are missing the &lt;b&gt;".$req_check[$i]."&lt;/b&gt; field&lt;/li&gt;\
";
				}
			}
		}
		if($email_fields != "")
		{
			$email_check=preg_split('/,/',$email_fields);
			$email_run=sizeof($email_check);
			for($i=0;$i&lt;$email_run;$i++)
			{
				$cur_email_name=$email_check[$i];
				$cur_email=$_POST[$cur_email_name];
				//if($cur_email=="" || !eregi($regex, $cur_email))
				if($cur_email=="" || !preg_match($regex, $cur_email))
				{
					$error_message.="&lt;li&gt;You are missing the &lt;b&gt;".$email_check[$i]."&lt;/b&gt; field or it is not a valid email address.&lt;/li&gt;\
";
				}
			}
		}
		return $error_message;
	}
// attachment function
	function getAttachments($attachment_fields, $message, $content_type, $border)
	{
		$att_message="This is a multi-part message in MIME format.\\r\
";
		$att_message.="--{$border}\\r\
";
		$att_message.=$content_type."\\r\
";
		$att_message.="Content-Transfer-Encoding: 7bit\\r\
\\r\
";
		$att_message.=$message."\\r\
\\r\
";

		$att_check=preg_split('/,/',$attachment_fields);
		$att_run=sizeof($att_check);
		for($i=0;$i&lt;$att_run;$i++)
		{
			$fileatt=$_FILES[$att_check[$i]]['tmp_name'];
			$fileatt_name=$_FILES[$att_check[$i]]['name'];
			$fileatt_type=$_FILES[$att_check[$i]]['type'];
			if (is_uploaded_file($fileatt))
			{
				$file=fopen($fileatt,'rb');
				$data=fread($file,filesize($fileatt));
				fclose($file);
				$data=chunk_split(base64_encode($data));
				$att_message.="--{$border}\
";
				$att_message.="Content-Type: {$fileatt_type}; name=\\"{$fileatt_name}\\"\\r\
";
				$att_message.="Content-Disposition: attachment; filename=\\"{$fileatt_name}\\"\\r\
";
				$att_message.="Content-Transfer-Encoding: base64\\r\
\\r\
".$data."\\r\
\\r\
";
			}
		}
		$att_message.="--{$border}--\
";
		return $att_message;
	}
// function to set content type
	function contentType($charset, $format)
	{
		if($format=="vert_table")
			$content_type="Content-type: text/html; charset=".$charset."\\r\
";
		else if($format=="horz_table")
			$content_type="Content-type: text/html; charset=".$charset."\\r\
";
		else
			$content_type="Content-type: text/plain; charset=".$charset."\\r\
";
		return $content_type;
	}
//////////////////////////
// end global functions //
//////////////////////////

////////////////////////////////
// begin procedural scripting //
////////////////////////////////
	// anti-spam empty field check
	if($_POST[$empty_field[$config]] != "")
	{
		$empty_message = "&lt;li&gt;This submission failed and was flagged as spam.&lt;/li&gt;\
";
	}
	// anti-spam character scan check
	if(strlen($character_scan[$config]) &gt; 0)
	{
		$spam_message="";
		$field_check=preg_split('/,/',$character_scan[$config]);
		$field_run=sizeof($field_check);
		for($i=0;$i&lt;$field_run;$i++)
		{
			$cur_field_name=$field_check[$i];
			$cur_field=$_POST[$cur_field_name];
			if(preg_match("/&lt;(.|\
)+?&gt;/", $cur_field) || preg_match("/\\[(.|\
)+?\\]/", $cur_field))
				$spam_message.="&lt;li&gt;This message contains disallowed characters.&lt;/li&gt;\
";
		}
	}
	// anti-spam time delay check
	if((strlen($time_delay[$config]) &gt; 0 && strlen($_POST["time"]) &gt; 0) || (strlen($time_delay[$config]) &gt; 0 && (strlen($_POST["time"]) == 0 || !$_POST["time"])))
	{
		if((time() - $_POST["time"]) &lt; $time_delay[$config])
			$time_message = "&lt;li&gt;This has been stopped by the timer, and is likely spam.&lt;/li&gt;\
";
	}
	// anti-spam CAPTCHA check
	if(strlen($captcha_codes[$config]) &gt; 0)
	{
		$captcha_check=preg_split('/,/',$captcha_codes[$config]);
		if(strtolower($_POST["captcha_entry"]) != strtolower($captcha_check[$_POST["captcha_code"]]))
			$captcha_message = "&lt;li&gt;CAPTCHA test did not match.&lt;/li&gt;\
";
	}
	// anti-spam max URL check
	if(strlen($max_url_fields[$config]) &gt; 0)
	{
		$max_url_message="";
		$field_check=preg_split('/,/',$max_url_fields[$config]);
		$field_run=sizeof($field_check);
		for($i=0;$i&lt;$field_run;$i++)
		{
			$cur_field_name=$field_check[$i];
			$cur_field=$_POST[$cur_field_name];
			preg_match_all("/http:/", $cur_field, $matches);
			if(count($matches[0]) &gt; $max_urls[$config])
				$max_url_message.="&lt;li&gt;This message contains too many URL's.&lt;/li&gt;\
";
		}
	}
	// set anti-spam flagging option
	if(strlen($empty_message.$spam_message.$time_message.$captcha_message.$max_url_message) &gt; 0 && strlen($flag_spam[$config]) == 0)
		$set_flag = 2;
	else if(strlen($empty_message.$spam_message.$time_message.$captcha_message.$max_url_message) &gt; 0 && strlen($flag_spam[$config]) &gt; 0)
		$set_flag = 1;
	else
		$set_flag = 0;
	// header injection check
   	$security_filter="";
	if(strlen($_POST[$reply_to_field[$config]]) &gt; 0)
	{
		//if(eregi($header_injection_regex,$_POST[$reply_to_field[$config]]))
		if(preg_match($header_injection_regex,$_POST[$reply_to_field[$config]]))
			$security_filter.="&lt;li&gt;Header injection attempt detected, mail aborted.&lt;/li&gt;\
";
		else
			$reply_to_field_checked=$_POST[$reply_to_field[$config]];
	}
	if(strlen($_POST[$reply_to_name[$config]]) &gt; 0)
	{
		//if(eregi($header_injection_regex,$_POST[$reply_to_name[$config]]))
		if(preg_match($header_injection_regex,$_POST[$reply_to_name[$config]]))
			$security_filter.="&lt;li&gt;Header injection attempt detected, mail aborted.&lt;/li&gt;\
";
		else
			$reply_to_name_checked=$_POST[$reply_to_name[$config]];
	}
	// check domain referrer and continue
	$domain_chk=checkReferer();
	if($domain_chk=="yes")
	{
		$error_message=checkFields($required_fields[$config], $required_email_fields[$config], $regex);
		if(strlen($error_message) &lt; 1 && strlen($security_filter) &lt; 1 && $set_flag &lt; 2)
		{
			// build appropriate message format for recipient
			$content_type=contentType($charset[$config], $mail_type[$config]);
			$message=buildTable($mail_type[$config], $mail_fields[$config], $mail_intro[$config], "recipient", $return_ip[$config]);
			// build header data for recipient message
			//$extra="From: ".$_POST[$reply_to_field[$config]]."\\r\
";
			$extra="From: ".$reply_to_name_checked." &lt;".$reply_to_field_checked."&gt;\\r\
";
			if($cc_tomail[$config]!="")
				$extra.="Cc: ".$cc_tomail[$config]."\\r\
";
			if($bcc_tomail[$config]!="")
				$extra.="Bcc: ".$bcc_tomail[$config]."\\r\
";
			if($mail_priority[$config]!="")
				$extra.="X-Priority: ".$mail_priority[$config]."\\r\
";
			// get attachments if necessary
			if($attachment_fields[$config]!="")
			{
				$semi_rand=md5(time());
				$border="==Multipart_Boundary_x{$semi_rand}x";
				$extra.="MIME-Version: 1.0\\r\
";
				$extra.="Content-Type: multipart/mixed; boundary=\\"{$border}\\"";
				$message=getAttachments($attachment_fields[$config], $message, $content_type, $border);
			}
			else
			{
				$extra.="MIME-Version: 1.0\\r\
".$content_type;
			}
			// send recipient email
			if($debug==1)
			{
				if($set_flag == 1)
					$debug_text.="&lt;p&gt;&lt;b&gt;Mail would have sent flagged for spam if not in debug mode.&lt;/b&gt;&lt;/p&gt;";
				else
					$debug_text.="&lt;p&gt;&lt;b&gt;Mail would have sent if not in debug mode.&lt;/b&gt;&lt;/p&gt;";
			}
			else if($debug==0)
			{
				if($set_flag == 1)
					$subject = $flag_spam[$config]." ".$subject[$config];
				else
					$subject = $subject[$config];
				mail("".$tomail[$config]."", "".stripslashes($subject)."", "".stripslashes($message)."", "".$extra."");
			}
			// autoresponse email if necessary
			if($send_copy[$config]=="yes")
			{
				// build appropriate message format for autoresponse
				$content_type=contentType($charset[$config], $copy_format[$config]);
				$message=buildTable($copy_format[$config], $copy_fields[$config], $copy_intro[$config], "autoresponder", $return_ip[$config]);
				// build header data for autoresponse
				$copy_tomail=$_POST[$copy_tomail_field[$config]];
				$copy_extra="From: ".$copy_from[$config]."\\r\
";
				// get autoresponse  attachments if necessary
				if($copy_attachment_fields[$config]!="")
				{
					$semi_rand=md5(time());
					$border="==Multipart_Boundary_x{$semi_rand}x";
					$copy_extra.="MIME-Version: 1.0\\r\
";
					$copy_extra.="Content-Type: multipart/mixed; boundary=\\"{$border}\\"";
					$message=getAttachments($copy_attachment_fields[$config], $message, $content_type, $border);
				}
				else
				{
					$copy_extra.="MIME-Version: 1.0\\r\
".$content_type;
				}
				// send autoresponse email
				if($debug==1)
				{
					if($set_flag == 1)
						$debug_text.="&lt;p&gt;&lt;b&gt;Autoresponder would have sent flagged for spam if not in debug mode.&lt;/b&gt;&lt;/p&gt;";
					else
						$debug_text.="&lt;p&gt;&lt;b&gt;Autoresponder would have sent if not in debug mode.&lt;/b&gt;&lt;/p&gt;";
				}
				else if($debug==0)
				{
					$send_copy = 1;
					//if($copy_tomail=="" || !eregi($regex,$copy_tomail))
					if($copy_tomail=="" || !preg_match($regex,$copy_tomail))
						$send_copy = 0;
					if($send_copy == 1)
					{
						if($set_flag == 1)
							$copy_subject = $flag_spam[$config]." ".$copy_subject[$config];
						else
							$copy_subject = $copy_subject[$config];
						mail("$copy_tomail", "".$copy_subject."", "$message", "$copy_extra");
					}
				}
			}
			// showing thanks pages from a successful submission
			if($thanks_page[$config]=="")
			{
				echo "&lt;h3&gt;".$thanks_page_title[$config]."&lt;/h3&gt;\
";
				echo "&lt;p&gt;".$thanks_page_text[$config]."&lt;/p&gt;\
";
				if(strlen($debug_text) &gt; 0)
					echo "&lt;p&gt;&lt;b&gt;&lt;i&gt;".$debug_text."&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;\
";
			}
			else
			{
				header("Location: ".$thanks_page[$config]);
			}
		}
		else
		{
			// entering error page options from missing required fields
			if($error_page[$config]=="")
			{
				echo "&lt;h3&gt;".$error_page_title[$config]."&lt;/h3&gt;\
";
				echo "&lt;ul&gt;\
";
				echo $security_filter.$empty_message.$error_message.$spam_message.$time_message.$captcha_message.$max_url_message;
				echo "&lt;/ul&gt;\
";
				echo "&lt;p&gt;".$error_page_text[$config]."&lt;/p&gt;\
";
			}
			else
			{
				header("Location: ".$error_page[$config]);
			}
		}
	}
	else
	{
		echo "&lt;h3&gt;".$error_page_title[$config]."&lt;/h3&gt;\
";
		// message if unauthorized domain trigger from referer checking option
		echo "&lt;p&gt;Sorry, mailing request came from an unauthorized domain.&lt;/p&gt;\
";
	}
//////////////////////////////
// end procedural scripting //
//////////////////////////////
}
else
{
	echo "&lt;h3&gt;Error&lt;/h3&gt;";
	echo "&lt;p&gt;No form data has been sent to the script&lt;/p&gt;\
";
}
if($footer[$config]!="")
	include($footer[$config]);
ob_end_flush();

	} else {

		// Don't process your code, deny the client from processing what they have inputed.
		header("Location: http://get-out-of-here-stupid-bot.com/");

	}

}
?&gt;

If it’s a human spamming you and being a d… Then just allow the person 1 time submission per IP Address. It’s the same technique, but instead of redirecting, give them the error saying “1 submission per IP Address” or don’t give them an error at all. What you do is store their IP Address in a table and when they submit the form, query and check to see if their IP Address already exists in the table, if it does then don’t let them submit and do the error part. If it doesn’t exist in the table, then store their IP Address in the table so that they only get 1 chance of submission.

I already checked and the person has used numerous IP addresses in the emails…f
For some reason this form’s anti-spam for time checking submitted is nto working if 3000 can be sent.

your honeypot code


<div class="honeypot"><input type="text" name="honeypot" placeholder="If you are a human, please skip this field."><br /></div>
<input type="text" name="name"><br />
<textarea name="textarea"></textarea><br />

shouldn’t the last </div> be after input name field?

I structured mine that way to see if this works. Ultimately, the evil goal of someone using your form to send spam hurts your rankings? or blacklists your IP (which in turn hurts your rankings?)

Well isn’t ranking based on how secure and how much traffic you get? If the traffic you get are bots and you want to block out the bots then you basically are going to reduce your rankings so that a legitimate user can explore your website freely. Once you implement a successful bot reject, you are going to kill more than half of your user base if your site was being spammed by bots. I maybe wrong, but that’s what I think.

And no, the only thing we’re really doing is we’re tricking the bot into filling everything out on the page including our honeypot. If you wrap the last </div> after the input name, then <input type=“text” name=“name”> will not show for a legitimate user and therefore will also block out real users.

My mistake and miscommunication on the input name field. forget that part.

Besides that I need a php email validator. as I all of these are “.tst” extensions

They are using / sending out emails using my old form from 3 hours ago but at the present time it arrives in my email box.

xMog, h would I get this into the form? anywhere?

I saw this elsewhere


function validStrLen($str, $min, $max){
    $len = strlen($str);
    if($len < $min){
        return "Field Name is too short, minimum is $min characters ($max max)".
    }
    elseif($len > $max){
        return "Field Name is too long, maximum is $max characters ($min min).";
    }
    return TRUE;
}

Then you can do something like this:

$errors['field_name'] = validStrLen($field, 12, 20);

The word “function” throws me off and makes me think it is javascript.

I want the amount field to be a minimum of 6 digits (not text or any characters) and less than 12 digits