単なるボットだと思いますが、どうすればこれを防ぐことができますか? 私は少なくともここでいくつかの検証を行っています-入力とphpの両方でHTML5が「必要」です。クライアント側の検証を忘れて、情報を入力せずに送信しようとすると、エラーが返されます(phpで)。
私ができない場合、ボットはどのようにしてそれを送信できますか? これに何を追加する必要がありますか?
<?php
$allowedFields = array(
'firstname',
'lastname',
'email',
'phone',
'address',
'prefer-email',
'prefer-snail ',
);
$requiredFields = array(
'firstname',
'lastname',
'email',
'phone',
'address',
'prefer-email',
'prefer-snail ',
);
$requiredEmail = array(
'email',
);
$errors = array();
foreach($_POST AS $key => $value) {
// first need to make sure this is an allowed field
if(in_array($key, $allowedFields)) {
$$key = $value;
// is this a required field?
if(in_array($key, $requiredFields) && $value == '') {
$errors[] = "The field $key is required.";
}
// is this a required field?
if(in_array($key, $requiredEmail) && !filter_var($value, FILTER_VALIDATE_EMAIL)) {
$errors[] = "A valid email is required.";
}
}
}
// were there any errors?
if(count($errors) > 0) {
$errorString = '<div class="error2"><h1>There was an error with the form.</h1><br />';
$errorString .= '<ul>';
foreach($errors as $error) {
$errorString .= "<li>$error</li>";
}
$errorString .= '</ul></div>';
// display the previous form
include 'index.php';
} else {
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$preferemail = $_POST['prefer-email'];
$prefersnail = $_POST['prefer-snail'];
$formcontent = "$firstname $lastname \r\n$email \r\n$phone \r\n$address \r\nPrefer Samples By: $preferemail $prefersnail \r\n";
//$recipient = "Tester <test@test.com>";
$recipient = "Tester <test@test.com>";
$subject = "Test.com Form Submission";
//$mailheader = "Landing Page <test@test.com>";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header("Location: http://www.test.com/thanks.html");
}