我有一个用普通HTML构建的网站,只有一个页面在php中,用于从联系我们页面生成电子邮件。
现在发生了什么,我的联系页面工作正常,但我每天凌晨3:10到凌晨3:12收到电子邮件同样的垃圾条目“1”
例如:
名称:1
电子邮件:我自己的电子邮件地址(与发件人(我)的电子邮件地址相同)
公司:1
地址:1
这是我遇到的主要问题。我正在使用Captcha来防止垃圾邮件。 请帮助:请参阅下面我使用过的代码: PHP电子邮件代码(example-form.php):
<?php session_start(); ?>
<?php
/** Validate captcha */
if (!empty($_REQUEST['captcha'])) {
if (empty($_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha']) {
header('Location: /captchacode.html');
exit();
//die("The verification code didn't match what was expected.");
//echo '<script>window.location.assign("/captchacode.html")</script>';
}
unset($_SESSION['captcha']);
}
if(thankyou_mail()){
$rediect = $_REQUEST['redirect'];
$_REQUEST ='';
//header("Location :".$_REQUEST['redirect']);
echo '<script>window.location.assign("'.$rediect.'")</script>';
}else{
//header("Location:404.html");
echo '<script>window.location.assign("/404.html")</script>';
}
function thankyou_mail() {
# Localize variables used in this subroutine.
$to =$_REQUEST['email'];
//$headers = "From:".$_REQUEST['recipient']."(".$_REQUEST['realname'].")\r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$date=date("Y/m/d");
# Check for Message Subject
$subject =$_REQUEST['subject'];
$message ="Thank You For Filling Out This Form.</b>";
$message .= "Below is what you submitted to ".$_REQUEST['recipient']." on ";
$message .="$date<p><hr size=1 width=75\%><p>\n";
$message .="<b> Name:</b> ".$_REQUEST['name']."<p>\n";
$message .="<b> Email:</b> ".$_REQUEST['email']."<p>\n";
$message .="<b> Company:</b> ".$_REQUEST['company']."<p>\n";
$message .="<b> Address:</b> ".$_REQUEST['address']."<p>\n";
$message .="<b> City:</b> ".$_REQUEST['city']."<p>\n";
$message .="<b> State:</b> ".$_REQUEST['state']."<p>\n";
$message .="<b> Zip:</b> ".$_REQUEST['zip']."<p>\n";
$message .="<b> Questions/Comments:</b> ".$_REQUEST['message']."<p>\n";
$headers = "From:".$_REQUEST['FormName']."<".$_REQUEST['from'].">\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//send_mail();
if ($to == $_REQUEST['from'])
{
header ('Location: /emailerror.html');
exit();
}
if(mail($to,$subject,$message,$headers)){
return true;
}else{
return false;
}
//mail($to,$subject,$message,$headers);
// return true;
}
/*
function send_mail() {
# Localize variables used in this subroutine.
$to =$_REQUEST['recipient'];
$headers = "From:".$_REQUEST['email']."(".$_REQUEST['realname'].")\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
# Check for Message Subject
$subject =$_REQUEST['subject'];
$message ="Below is the result of your feedback form. It was submitted by\n";
$message .= $_REQUEST['realname']." (".$_REQUEST['email'].") on $date<p><hr size=1 width=75\%><p>\n";
$message .="<b> Name:</b> ".$_REQUEST['name']."<p>\n";
$message .="<b> Email:</b> ".$_REQUEST['email']."<p>\n";
$message .="<b> Company:</b> ".$_REQUEST['company']."<p>\n";
$message .="<b> Address:</b> ".$_REQUEST['address']."<p>\n";
$message .="<b> City:</b> ".$_REQUEST['city']."<p>\n";
$message .="<b> State:</b> ".$_REQUEST['state']."<p>\n";
$message .="<b> Zip:</b> ".$_REQUEST['zip']."<p>\n";
$message .="<b> Questions/Comments:</b> ".$_REQUEST['message']."<p>\n";
mail($to,$subject,$message,$headers);
return true;
}
*/
与我们联系(HTML PAGE)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Contact Us - </title>
<meta name="keywords" content="KEYWORDS GO HERE. 12 KEYWORDS MAX, & ONLY 3 REPEATED WORDS" />
<meta name="description" content="DESCRIPTION GOES HERE. 160 CHARACTERS" />
<link rel="stylesheet" type="text/css" href="styles.css" title="standard" />
<link rel="icon" href="/images/favicon.ico" />
<script src="scripts/rollover.js" type="text/javascript"></script>
</head>
<script src="lib/jquery.js"></script>
<script src="jquery.validate.js"></script>
<script>
//$.validator.setDefaults({
// submitHandler: function() { }
//});
$().ready(function() {
// validate signup form on keyup and submit
$("#signupForm").validate({
rules: {
name: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
company: {
required: true,
minlength: 5
},
address: {
required: true,
minlength: 2
},
city: "required",
state: "required",
zip: "required",
captcha:"required"
},
messages: {
name: {
required: "Please enter a username",
minlength: "Your username must consist of at least 2 characters"
},
company: "Please enter a company",
email: "Please enter a valid email address",
address: "Please enter a address",
city: "Please enter a city",
state:"Please enter a state",
zip: "Please enter a zip",
captcha : "Please enter a letters of Image"
}
});
});
</script>
<style type="text/css">
label.error {
margin-left: 10px;
width: auto;
display: inline;
color: red;
}
#newsletter_topics label.error {
display: none;
margin-left: 103px;
}
</style>
<body>
<div id="headerWrap">
<div id="header">
<h1 id="logo">LLC</h1>
<div id="contact"><a href="contact.html">CONTACT US</a></div>
</div><!-- end #header -->
</div><!-- end #headerWrap -->
<div id="navWrap">
<div id="nav">
<ul class="nav1">
<li><a href="index.html"><img class="imgover" src="images/nav-home.jpg" width="129" height="46" /></a></li>
<li><a href="about.html"><img class="imgover" src="images/nav-about.jpg" width="135" height="46" /></a></li>
<li><a href="lobbying.html"><img class="imgover" src="images/nav-lobbying.jpg" width="168" height="46" /></a></li>
<li><a href="ally-development.html"><img class="imgover" src="images/nav-ally.jpg" width="237" height="46" /></a></li>
<li><a href="strategic-consulting.html"><img class="imgover" src="images/nav-strategic.jpg" width="231" height="46" /></a></li>
</ul>
</div><!-- end #nav -->
</div><!-- end #navWrap -->
<div id="contentWrap">
<div id="content">
<br clear="all" />
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="c2L">
<div><a href="contact.html"><img src="images/contact.jpg" /></a></div>
</td>
<td class="c2R">
<div>
<h2 class="normh2">Contact Us</h2>
<form method="post" id="signupForm" action="example-form.php">
<input name="FormName" type="hidden" />
<!-- <input name="username" type="hidden" />-->
<input name="realname" type="hidden" />
<input name="subject" type="hidden" />
<input name="thankurl" type="hidden" value="thank.html" />
<!-- <input name="recipient" type="hidden" value="emailid" />-->
<input name="email" type="hidden" value="" />
<input name="redirect" type="hidden" value="/thank.html" />
<input type="hidden" name="from" />
<table id="contactTable" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td id="contactTableL">Name</td>
<td id="contactTableR"><input type="text" name="name" size="35" /></td>
</tr>
<tr>
<td id="contactTableL">Email</td>
<td id="contactTableR"><input type="text" name="email" size="35" /></td>
</tr>
<tr>
<td id="contactTableL">Company</td>
<td id="contactTableR"><input type="text" name="company" size="35" /></td>
</tr>
<tr>
<td id="contactTableL">Address</td>
<td id="contactTableR"><input type="text" name="address" size="35" /></td>
</tr>
<tr>
<td id="contactTableL">City</td>
<td id="contactTableR"><input type="text" name="city" size="35" /></td>
</tr>
<tr>
<td id="contactTableL">State</td>
<td id="contactTableR"><input type="text" name="state" size="35" /></td>
</tr>
<tr>
<td id="contactTableL">Zip</td>
<td id="contactTableR"><input type="text" name="zip" size="35" /></td>
</tr>
<tr>
<td id="contactTableL">Questions/<br />Comments</td>
<td id="contactTableR"><textarea name="message" rows="9" cols="31" ></textarea></td>
</tr>
<tr>
<td id="contactTableL">Verification<br />
<img src="captcha.php" id="captcha" /><br/>
<!-- CHANGE TEXT LINK -->
<a href="javascript:void(0)" onclick=" document.getElementById('captcha').src='captcha.php?'+Math.random();
document.getElementById('captcha-form').focus();"
id="change-image">Not readable? Change text.</a>
</td>
<td id="contactTableR">
<input type="text" name="captcha" id="captcha-form" autocomplete="off" />
</td>
</tr>
<tr>
<td> </td>
<td><input id="submitButton" type="submit" name="submit" value="SUBMIT" /></td>
</tr>
</table>
</form>
</div>
</td>
</tr>
</table>
</div><!-- end #content -->
</div><!-- end #contentWrap -->
<div id="footerWrap">
<div id="footer">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="c2L2">
<div><img src="images/logo-footer.jpg" alt="" width="216" height="103" /></div>
</td>
<td class="c2R2">
<ul class="nav2">
<li><a href="index.html">HOME</a></li>
<li><a href="about.html">ABOUT</a></li>
<li><a href="lobbying.html">LOBBYING</a></li>
<li><a href="ally-development.html">ALLY<br />DEVELOPMENT</a></li>
<li><a href="strategic-consulting.html">STRATEGIC<br />CONSULTING</a></li>
<li class="last"><a href="contact.html">CONTACT US</a></li>
</ul>
<br clear="all" />
<p><span>Copyright © 2012 LLC</span> Website Design by <a href="http://www.2broz.com">Web Design CT</a></p>
</td>
</tr>
</table>
</div><!-- end #footerContain -->
</div><!-- end #footerWrap -->
</body>
</html>
我认为这些是有用的代码,如果您需要更多帮助,请告诉我。
答案 0 :(得分:0)
你的if-else子句中存在逻辑错误:
if (!empty($_REQUEST['captcha'])) {
if (empty($_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha']) {
header('Location: /captchacode.html');
exit();
}
unset($_SESSION['captcha']);
}
如果有人填写验证码,您只能测试验证码是否正确。因此,如果有人设法在将验证码留空的情况下发送表单,则测试将通过,邮件将被发送。如果您将测试更改为以下内容,则应该可以正常工作:
if( empty($_REQUEST['captcha'])
|| empty($_SESSION['captcha'])
|| trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha']) {
// captcha not filled in, or captcha not correct.
}
答案 1 :(得分:0)
如果您能够在垃圾邮件收件箱中看到邮件,则邮件代理的声誉很低。尝试在标题中添加发件人地址并检查。
此问题已在早些时候得到解答。 PHP mail() form sending to GMAIL spam