【发布时间】:2014-12-11 01:37:59
【问题描述】:
我尝试在此表单中添加验证码,如果您愿意,请检查链接。
This is the link from Stackoverflow
但是当我输入验证码错误时,我无法使其正常工作,没有任何反应,我仍然收到邮件。
<?php
session_start();
$cap = 'notEq';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_POST['captcha'] == $_SESSION['cap_code']) {
// Captcha verification is Correct. Do something here!
$cap = 'Eq';
} else {
// Captcha verification is wrong. Take other action
$cap = '';
}
$to = "exmaple@mail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$ip = $_POST['ip'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . " " . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
下面是验证码和提交按钮。
<!-- Captcha -->
<input type="text" name="captcha" id="captcha" maxlength="6" size="6"/>
<!-- Submit Button -->
<input type="submit" id="captcha" name="captcha" value="Submit">
那我在这里做错了什么?
感谢您的帮助。
【问题讨论】:
-
您在哪里运行设置验证码值并将其存储在 $_SESSION['cap_code'] 上的代码
-
@RiggsFolly 脚本正在运行,直到我从 ($to = "example@mail.com") 到 (end php tag ?>)
-
你可以使用谷歌recaptcha而不是尝试创建自己的?它会让你更简单,不同的捕获图像的数量将比你个人制作的要多得多google.com/recaptcha/intro