这个表单工作得很好,如果你填好了,它会发送邮件,如果你没有填好所有的输入,它会警告你必须填写,并且在你填好之前不会发送表单。
我正在使用我使用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 }
update:原来这是服务器的一些问题,所以他们告诉我,我无能为力。
使用客户端验证的事实并不能保证在后端总是接收到有效的输入。无论您是否在浏览器中执行验证,您也应该始终在PHP脚本中执行验证。在某些情况下,用户可能会禁用JS,甚至会向您的服务器端脚本发送恶意框架请求。