1

我的客户通过我的电子邮件接收空白表格时遇到了一些问题。

我正在使用以下表格

 <form method="get" action="javascript:contactForm()" class="form">
            <div class="alertForm"><!-- Error's go in here --></div>
            <div class="innerForm">
                <div class="placeholder">Your Name</div>
              <input type="text" name="name" value="" id="name" placeholder="">
                <div class="placeholder">Your Phone Number</div>
              <input type="text" name="number" value="" id="number" placeholder="">
              <select name="time" id="time">
                <option value="null">Please Select A Time</option>
                <option value="09:00 - 11:00">09:00 - 11:00</option>
                <option value="11:00 - 13:00">11:00 - 13:00</option>
                <option value="13:00 - 15:00">13:00 - 15:00</option>
                <option value="15:00 - 17:00">15:00 - 17:00</option>
                <option value="17:00 - 19:00">17:00 - 19:00</option>
              </select>
              <input type="submit" value="Call Me Back">
            </div>
          </form>

和 PHP 帖子

     $name = $_POST['name']; $number = $_POST['number']; $time = $_POST['time'];
     $subject = "[CALLBACK] ".$name." - ".$number;
     $to = "clown@thecircus.co.uk";
     $headers = "From:" . "website@thecircus.co.uk";
     $message = $name." would like you to call them back on ".$number." between ".$time;

     if(mail($to, $subject, $message, $headers)){ echo "We will call you within the time       you've selected. If not today, then the next day.<br><br>Thank you."; }
     else{ echo "Something's gone horribly wrong! PANIC."; }

如果我尝试它似乎工作正常 - 但是我每天收到大约 7 封空白电子邮件。我不确定这些是垃圾邮件还是它们实际上是联系表格但丢失了数据?

任何帮助将不胜感激。

4

1 回答 1

2

您的表单method设置为,get但您正在尝试访问$_POSTPHP 中的变量。将您的表单切换到method="post"或使用$_GET而不是$_POST(尽管我建议使用 POST)。

但是,您还应该在表单中添加一些服务器端验证。至少检查是否已将某些内容输入到您的表单字段中。

于 2012-05-05T10:12:03.743 回答