PHP来自Captcha和电子邮件验证

时间:2014-01-20 22:06:04

标签: php forms validation

我有一张表格@:http://www.shannonmoving.com/sendquote.php

目前,用户只需输入验证码详细信息并将表单发送为空。 我需要它,因此需要姓名和电子邮件地址。

我设置了spry验证,但验证码似乎绕过了这个。

这是PHP

<?php
if (($captcha_error == "on") && !isset($email)){
print("<div id=\"\" style=\"border: 1px solid #FFF; background: ##59A715; padding: 10px;\">There was a captcha error. Please go back and re-enter the captcha security code text.</div>");
$sent = "on";
} else

if (($_GET['send'] == "on")&&($captcha_error == "")) {

$message = "
____________________________

    CUSTOMER DETAILS
____________________________

FULL NAME:              $_POST[fullname]
EMAIL:                  $_POST[email]
PRIMARY PHONE:          $_POST[primaryphone]
SECONDARY PHONE:        $_POST[secondaryphone]
REFERRED BY:            $_POST[referredby]
PREFERRED MOVE DATE:    $_POST[preferredmovedate]
ALTERNATE MOVE DATE:    $_POST[alternatemovedate]
MOVING OUT OF:          $_POST[movingoutof]
MOVING INTO:            $_POST[movinginto]
PACKING REQUIRED:       $_POST[packing]

etc,etc


$name = "$_POST[First] $_POST[Last]";
$email = "$_POST[email]";


mail($to, $subject, $message, "From: $name <$email> \nX-Mailer:PHP/" . phpversion());
mail($to2, $subject, $message, "From: $name <$email> \nX-Mailer:PHP/" . phpversion());
mail($to3, $subject, $message, "From: $name <$email> \nX-Mailer:PHP/" . phpversion());
mail($to4, $subject, $message, "From: $name <$email> \nX-Mailer:PHP/" . phpversion());

?>

<div style="background: #24420F; padding: 10px; border: 1px solid #FFF;">
Thank you for taking the time to fill out our online form it has been <br/>Successfully Sent!
</div>


<?php

$sent = "on";
} 


if ($sent == "") {
?>

2 个答案:

答案 0 :(得分:0)

在名称和电子邮件输入元素上添加属性“required”(假设为html 5)

<input name="email" type="email" required/>

答案 1 :(得分:0)

我不确定,但你可以尝试改变第一行:

if (($captcha_error == "on") && !isset($email)){

通过

if (($captcha_error == "on") || !isset($email)){