表单工作正常,如果您填写,它会发送电子邮件,如果您没有填写所有输入,它会警告您必须这样做并且不会发送表单,直到您执行它
我正在使用jquery.validate.js,但最近,我一直在收到空白电子邮件。如果验证工作正常(我甚至在旧浏览器中测试过),为什么它会向我发送空白电子邮件?
HTML
<form id="contact-form" method="post" action="contacto.php">
<fieldset>
<div class="control-group">
<div class="controls">
<input name="name" id="name" type="text" placeholder="Nombre" required>
</div>
</div>
<div class="control-group" style="margin-top:10px;">
<div class="controls">
<input type="text" name="email" id="email" placeholder="Email" required>
</div>
</div>
<div class="control-group" style="margin-top:10px;">
<div class="controls">
<textarea class="input-xlarge" name="message" id="message" rows="3" placeholder="Mensaje"></textarea>
</div>
</div>
<div class="form-actions">
<button type="submit" class="demo-pricing demo-pricing-1">Submit</button>
<button type="reset" class="demo-pricing demo-pricing-1">Cancel</button>
</div>
</fieldset>
</form>
PHP
$subject = "Web";
$to = 'contact@web.com';
$header .= "Content-Type: text/html; charset=UTF-8";
$headers = "From: " . $_POST["name"];
$headers .= "<" . $_POST["email"] . ">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-Path: " . $_POST["email"];
$message .= "************************************************** \n";
$message .= "Contact \n";
$message .= "************************************************** \n\n";
$message .= "Nombre: " . $_POST["name"] . "\r";
$message .= "E-mail: " . $_POST["email"] . "\r";
$message .= "Mensaje: " . $_POST["message"] . "\r";
$mail_sent = mail($to, $subject, $message, $headers);
if ($mail_sent == true){ ?> <script language="javascript" type="text/javascript"> window.alert('behold, we are aware of you')
window.location.href='index.html'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('nope, try again'); </script> <?php }
更新:原来这是服务器的一些问题,所以他们告诉我,我无能为力。
答案 0 :(得分:0)
您使用客户端验证的事实并不能确保您始终在后端接收有效输入。您也应该始终在PHP脚本中进行验证,无论您是否在浏览器中执行此操作。在某些情况下,用户可能会禁用JS,甚至会对服务器端脚本发出恶意框架请求。