我遇到一些问题,客户通过我的电子邮件收到空白表格。
我使用以下表格
<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封空白电子邮件。我不确定这些是垃圾邮件还是实际上是联系表格,但是他们丢失了数据?
任何帮助将不胜感激。
答案 0 :(得分:2)
您的表单method
设置为get
,但您尝试访问PHP中的$_POST
个变量。将表单切换为method="post"
或使用$_GET
代替$_POST
(虽然我建议使用POST)。
但是,您还应该在表单中添加一些服务器端验证。至少检查表格字段中是否输入了某些内容。