我正在尝试在 wordpress 网站上为我的自定义表单使用蜜罐技术。我的表格看起来像这样。
<form id="form-1"
action="<?php echo get_template_directory_uri(); ?>/mail.php" method="post" class="order__form form">
<p class="form__title">Order and Receive 30% off</p>
<p class="form__text">fill out this form so you can get sale</p>
<input type="text" name="name" class="form__item" placeholder="Your name">
<input type="email" name="email" required class="form__item" placeholder="Email address">
<p class="robotic" id="pot">
<label>If you're human leave this blank:</label>
<input name="robotest" type="text" id="robotest" class="robotest" />
</p>
<input type="submit" value="Send" class="button form__button">
</form>
输入名称robotest
以在服务器端进行验证。
这是mail.php
代码:
<?php
$mess = '';
$mess .= '<hr>';
if($_POST['robotest'] != ''){
$error = "You are a gutless robot.";
} else {
if(isset($_POST['name'])) {
$name = substr(htmlspecialchars(trim($_POST['name'])), 0, 100);
$mess .= '<b>Имя отправителя: </b>' . $name . '<br>';
}
if(isset($_POST['email'])) {
if($_POST['email']!=''){
$email = substr(htmlspecialchars(trim($_POST['email'])), 0, 100);
$mess .= '<b>E-mail: </b>' . $email . '<br>';
}
}
}
$mess .= '<b>Заявка пришла со страницы:</b> ' . $_SERVER["HTTP_REFERER"] .'<br>';
$mess .= '<hr>';
require 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->AddAddress('xxx2xxx.com','');
$mail->IsHTML(true);
$mail->CharSet = "UTF-8";
$mail->Subject = "new";
$mail->From = "new";
$mail->FromName = "new";
$mail->Body = $mess;
if ($mail->Send()) {
header('Location: ../');
} else {
die ('Mailer Error: ' . $mail->ErrorInfo);
}
header("Location: /thanks/");
?>
当我添加验证时robotest
,此脚本不起作用。