我已经通过了大量的形式,似乎无法找到答案。我已经用我的PHP表单开启和关闭了几天这个问题。希望在这里找到帮助。形式是完美的。所有字段在提交时都正常工作,但似乎总是在一天到两天之后发送的第二个表单是空白的。如果有任何建议,为什么会发生这种情况,那将会很有帮助。
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
// recipient address
$to = "grandforkssuites@gmail.com";
// subject of email
$re = "Contact Us Form Delivery";
// message creation
$contact = "Name:".$name."\nEmail:".$email."\nSubject:".$subject."\r\n";
$txt = "Comments:".$comments."\r\n";
$fmsg = $contact."\r\n".$txt;
$msg = wordwrap($fmsg, 70);
// send email
mail($to,$re,$msg);
?>
<form action="contact1.php" method=post name="form" id="form">
<div class="col_w280 float_l">
<p><em>
<label for="author">Name:</label> <input type="text" id="name" name="name" class="required input_field" />
<div class="cleaner_h10"></div>
<label for="email">Email:</label> <input type="text" id="email" name="email" class="validate-email required input_field" />
<div class="cleaner_h10"></div>
<label for="email">Phone:</label> <input type="text" id="phone" name="phone" class="required input_field" />
<div class="cleaner_h10"></div>
<label for="subject">Subject:</label> <input type="text" name="subject" id="subject" class="input_field" />
<div class="cleaner_h10"></div>
</div>
<div class="col_w280 float_r">
<label for="text">Comments:</label> <textarea id="comments" name="comments" rows="0" cols="0" class="required input_field"></textarea>
<div class="cleaner_h10"></div></em></p>
<input name=submit type=submit id="submit" onClick="MM_validateForm('name','','R','email','','RisEmail');return document.MM_returnValue" value="Send">
</div></form>
答案 0 :(得分:1)
向PHP添加验证,否则即使没有通过POST发送任何值,只需访问该页面即可发送空白电子邮件。很可能搜索引擎或此类机器人只是爬行。
请检查其POST
<?php
if($_SERVER['REQUEST_METHOD']==='POST'){
//put code here
}
?>
并检查您的值是否设置为min-max length ect
<?php
...
...
...
//Comments
if(empty($_POST['comments'])){
//comments empty, do or set something
}else if(strlen($_POST['comments']) < 5){
//not long enough, do or set something
}else if(strlen($_POST['comments']) > 50){
//too large, do or set something
}
?>
最重要的是检查电子邮件确实是一封电子邮件..
<?php
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
//is an email
}else{
//not an email
}
?>
此外,您还想添加一个基本验证码,否则您每天可以享受1000次营销/垃圾邮件。
祝你好运,实施它。