PHP 简单的PHP联系表格+ jscript验证+反机器人
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 简单的PHP联系表格+ jscript验证+反机器人相关的知识,希望对你有一定的参考价值。
CSS
<style type="text/css"> #botty {display:none;} <style>
Javascript
<script type="text/javascript">
function checkform(form){
// check first name
if (form.FirstName.value == "") {
alert( "Please enter your First Name." );
form.FirstName.focus();
return false ;
}
// check last name
if (form.LastName.value == "") {
alert( "Please enter your Last Name." );
form.LastName.focus();
return false ;
}
// check email field
if (form.email.value == "") {
alert( "Please enter your Email Address." );
form.email.focus();
return false ;
}
// check for valid email addy
var apos=form.email.value.indexOf("@");
var dotpos=form.email.value.lastIndexOf(".");
if (apos<1||dotpos-apos<2){
alert("Not A Valid Email Address!");
return false;
}
// ** END **
return true ;
}
</script>
HTML
<form action="contact_handle.php" method="post" name="formy" id="formy">
<p>* Required</p>
<table cellspacing="0" cellpadding="2" border="0" class="webform">
<tbody>
<tr>
<td><label for="Title">Title</label>
<br />
<select name="Title" id="Title" class="cat_dropdown_smaller">
<option value="126631">DR</option>
<option value="126629">MISS</option>
<option value="126627" selected="selected">MR</option>
<option value="126628">MRS</option>
<option value="126630">MS</option>
</select></td>
</tr>
<tr>
<td><label for="FirstName">First Name</label>
<br />
<input name="FirstName" type="text" class="cat_textbox" id="FirstName" size="35" maxlength="255" />
*</td>
</tr>
<tr>
<td><label for="LastName">Last Name</label>
<br />
<input name="LastName" type="text" class="cat_textbox" id="LastName" size="35" maxlength="255" />
*</td>
</tr>
<tr>
<td><label for="email">Email Address</label>
<br />
<input name="email" type="text" class="cat_textbox" id="email" size="35" maxlength="255" />
*</td>
</tr>
<tr>
<td><label for="comments">Comments/Enquiries</label>
<br />
<textarea name="comments" cols="45" rows="8" class="cat_listbox" id="comments" onkeydown="if(this.value.length&gt;=1024)this.value=this.value.substring(0,1023);"></textarea></td>
</tr>
<tr>
<td><input name="subscribe" type="checkbox" id="subscribe" value="yes" />
Subscribe to: Email List Signup</td>
</tr>
<tr>
<td><input type="submit" class="cat_button" value="Submit" id="catwebformbutton" />
<span id="formHide"><input type="text" id="botty" name="botty" /></span>
</td>
</tr>
</tbody>
</table>
</form>
PHP
<?php
//form data
$FirstName = strip_tags($_POST['FirstName']);
$LastName = strip_tags($_POST['LastName']);
$email = strip_tags($_POST['email']);
$subscribe = strip_tags($_POST['subscribe']);
$comments = strip_tags($_POST['comments']);
// prove if a bot has entered data
$botty = strip_tags($_POST['botty']);
if($botty != NULL){
echo "barghh! darn bot!";
die;
}
// the email address where the script will email the form results to
$to = "recipientemail@here.com";
// where the email will look like it is sent from
$from = "info@atsomedomain.com";
$subject = "Email from your website";
$body = "Email from your website" . "
";
$body .= "Name: " . $FirstName . $LastName . "
";
$body .= "Email: " . $email . "
";
$body .= "Newsletter: " . $subscribe . "
";
$body .= "Comments: " . $comments . "
";
$headers = "From: $from" . "
";
$headers .= "Reply-To: $from" . "
";
$headers .= "Return-Path: $from" . "
";
// mail(to,subject,body,headers);
$isMailed = mail($to, $subject, $body, $headers);
if($isMailed){
echo "Thank you for your inquery, " . $FirstName . " " . $LastName . " We will get back to you shortly.";
}else{
echo "There seemed to be a problem";
}
?>
以上是关于PHP 简单的PHP联系表格+ jscript验证+反机器人的主要内容,如果未能解决你的问题,请参考以下文章