私は素人のWebデザイナーです。私はstackoverflow.comや他のウェブサイトで検索しましたが、私はこの問題の多くの修正を見つけましたが、それらは間違っている)。私はより多くの知識を持つ人が簡単な修正で私を助けたり、私が見つけた修正の1つを実装する方法を教えてくれることを望んでいます。PHPウェブ連絡フォームのスパムを防ぐ
問題:私のビジネスのウェブサイトには非常に単純なPHPの連絡フォームがあります。それは長年にわたり素晴らしい仕事をしてきましたが、先週はハッキングされました。私は今、コメントなしで1日に数百件の連絡先フォームの投稿を受け取り、(明らかに有効な)電子メールアドレスと、名前フィールドに文字列(「58ee8b52eef46」など)を持っています。
私はこのスパムを防ぐためにいくつかの方法を試しています。彼らは私のPHPフォームを壊すか、スパムを防ぐことはできません。 可能であれば、私はCaptcha歪みテキストテストを必要とせず、フォームのすべてのフィールドを入力する必要はありません。ここで
は私の完全なPHPコードです:あなたが取得しているスパムコメントがない場合は
<?php
if(isset($_POST['email'])) {
$email_to = "[email protected]";
$email_subject = "website form submission";
function died($error) {
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name'];
$email_from = $_POST['email'];
$telephone = $_POST['telephone'];
$comments = $_POST['comments'];
$error_message = "";
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for contacting us. We will be in touch with you soon. You will now be redirected back to example.com.
<META http-equiv="refresh" content="2;URL=http://www.example.com">
<?php
}
die();
?>
あなたはcaptcha' – RiggsFolly
イム 'を見てきました確かに私は言いましたあなたの前にこれをdが、しかし、Googleのrecaptchaは今ほとんどの正当な訪問者のために不可視です。 – Steve
私はCaptchaの使用を検討しました。しかし私は私のウェブサイトできれいな外観を保つためにcaptchaを使用しない修正を好むだろう。 – user7858610