简体   繁体   English

反垃圾邮件安全问题php联系表格

[英]anti spam security question php contact form

I have a working contact field. 我有一个工作联系字段。 Although I am using standard spam-protection things like honeypot etc. I am getting spam nearly every day. 尽管我使用的是标准的垃圾邮件防护工具,例如蜜罐等。但我几乎每天都会收到垃圾邮件。 So I thought I might us an security question. 所以我想我可能会提出一个安全问题。 So Ive adde this: 所以我添加了这个:

Spam-question: Which colour has the sky? (lowercase) <input name="spamprotection">

Now I want to only send the form if this question is answered right otherwise it should show the error message. 现在,我只想在正确回答此问题的情况下发送表格,否则它将显示错误消息。 But its not sending anymore but still showing the success message. 但是它不再发送但仍显示成功消息。 What am I doing wrong? 我究竟做错了什么?

Ive added this to the send-sequence and before it was working properly: !empty($_POST['spamprotection']) || ($_POST["spamprotection"] = 'blau') || 我已经将此添加到发送序列中,然后才能正常工作: !empty($_POST['spamprotection']) || ($_POST["spamprotection"] = 'blau') || !empty($_POST['spamprotection']) || ($_POST["spamprotection"] = 'blau') ||

// Send the email. 

if (!empty($_POST['spamprotection']) || ($_POST["spamprotection"] = 'blau') ||  mail($to, $subject, $message, $header)) {

    $result = ["color" => "green", "msg" => "Ich habe Ihre Mail erhalten und melde mich in Kürze!"];

    if ($file_type) {

      $result['msg'] .= "";

    }

} else {

    $result = ["color" => "red", "msg" => "Nachricht konnte nicht gesendet werden. Bitte senden Sie mir Ihre Anfrage an bm-translations@email.de"];

}

Your logic in your if statement is not valid. 您的if语句中的逻辑无效。

You need to change your code to this. 您需要将代码更改为此。

if (isset($_POST['spamprotection']) && $_POST["spamprotection"] == 'blau') {

    $result = ["color" => "green", "msg" => "Ich habe Ihre Mail erhalten und melde mich in Kürze!"];
    mail($to, $subject, $message, $header);

    if ($file_type) {

      $result['msg'] .= "";

    }

} else {

    $result = ["color" => "red", "msg" => "Nachricht konnte nicht gesendet werden. Bitte senden Sie mir Ihre Anfrage an bm-translations@email.de"];

}

When it comes to equality: 关于平等:

$a = '5'; //This sets $a = 5(string);
$b = 5; //This sets $b = 5(int);
$a == $b;  //This checks to see if $a is equal to $b. Will return true.
$a === $b; //This is a strict comparison of $a & $b.  It checks to see if $a is equal to $b as well as the type.  Meaning $a(string) is equal to $b(int). Will return false.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM