在电子邮件中接收未填写的联系表格

时间:2016-01-15 09:41:46

标签: javascript php html forms email

所以在最近2个月里,我的网站在线,我收到了来自联系表格的2封正常电子邮件,还有30封空的未填写表单电子邮件。我还使用验证器http://faireware.de/js/jquery.form-validation-and-hints.js。 奇怪的是,当我没有填写表格并按发送时,我不会将这些空白用于电子邮件。它会以某种方式自动发生......垃圾邮件机器人或其他东西,可能吗?

我的HTML代码是:

<form method="post" action="contactengine.php">

  <div class="field required">
    <p>Name<br>
    <input class="text verifyText hint" name="name" type="text" size="25" title="*Ihr Name..."></p>
  </div><!--/field--> 

  <div class="field required ">
    <p>E-Mail<br>
    <input class="email verifyMail hint " name="email" type="text" size="25" title="*Ihre E-Mail-Adresse..."></p>
    </div><!--/field-->

    <div class="field required ">
      <p>Nachricht<br>
      <textarea name="message" rows="50" cols="50" title="*Schreiben Sie Ihre Nachricht..." class="hint "></textarea></p>
    </div><!--/field-->
  <p><input class="submit" type="submit" value="Senden"></p>
</form>

和我的contactengine.php是:

<?php

$Subject = "Kontaktformular - FaireWare";
$Name = Trim(stripslashes($_POST['name'])); 
$Email = Trim(stripslashes($_POST['email'])); 
$Message = Trim(stripslashes($_POST['message'])); 
$EmailFrom = $Email;
$EmailTo = "info@faireware.de";

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n\n";
$Body .= "E-Mail: ";
$Body .= $Email;
$Body .= "\n\n";
$Body .= "Nachricht: ";
$Body .= "\n";
$Body .= $Message;
$Body .= "\n\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: $Email");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

空的电子邮件表单确实是这样的:

Name: 

E-Mail: 

Nachricht:

它是自动完成的吗?它如何超越验证......?我不知道PHP和非常少的java,所以有谁知道问题出在哪里?

谢谢!

2 个答案:

答案 0 :(得分:2)

尝试将服务器端代码更新为牢不可破,以避免垃圾邮件。这是一些建议。

  1. Google Recaptcha
  2. Honeypot Technique
  3. 还要进行服务器端检查。

    if(isset($_POST['name'])){
     // Save the data or do the further processing
    }
    

    建议:开发安全应用程序时,不要依赖客户端验证。

答案 1 :(得分:2)

您可以试试这个,我已经使用基本的服务器端验证修改了您的代码。

<?
if(count($_POST) > 0)
{
    $Subject = "Kontaktformular - FaireWare";
    $Name = trim(stripslashes($_POST['name'])); 
    $Email = trim(stripslashes($_POST['email'])); 
    $Message = trim(stripslashes($_POST['message'])); 
    $EmailTo = "info@faireware.de";

    $validationOK = true;
    if(empty($Name) || empty($Email) || empty($Message)){
        $validationOK = false;
    }

    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }
    else
    {
        // prepare email body text
        $Body = "";
        $Body .= "Name: ";
        $Body .= $Name;
        $Body .= "\n\n";
        $Body .= "E-Mail: ";
        $Body .= $Email;
        $Body .= "\n\n";
        $Body .= "Nachricht: ";
        $Body .= "\n";
        $Body .= $Message;
        $Body .= "\n\n";
        $headers = 'From: $Email' . "\r\n";

        // send email 
        $success = mail($EmailTo, $Subject, $Body, $headers);

        // redirect to success page 
        if ($success){
          print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.html\">";
        }
        else{
          print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
        }
    }
}
?>

我改变了什么?

添加开始检查,如果$_POST数组不是0,则添加empty()的基本验证。 If任何一个字段为空的电子邮件都不会发送else您将收到该电子邮件。