-1
我有一个联系表单,工作正常。不过,我正在尝试使用jQuery validation plugin来检查提交前是否还有空的字段,但是当我添加插件时,我不再收到任何电子邮件。PHP的邮件功能不适用于jQuery验证插件
的代码如下:
内contact.html
$(document).ready(function(){
$("form").validate({
submitHandler: function() {
alert("Thank you for submitting your information.");
},
});
});
<form class="cmxform" id="myform" method="post" action="contact.php">
<fieldset>
<p><label for="cname">Name:</label> <input type="text" id="cname" name="name" maxlength="255" class="required" /></p>
<p><label for="cemail">Email:</label> <input type="text" id="cemail" name="email" maxlength="255" class="required email" /></p>
<p><label for="tel">Tel:</label> <input type="text" id="tel" name="tel" maxlength="15" class="required" /></p>
<p><label for="service">Service:</label>
<select name="service">
<option value="option1">Option1</option>
<option value="option2">Option2</option>
<option value="option3">Option3</option>
</select>
</p>
<p><label for="comments">Comments:</label><textarea class="textarea" id="comments" name="comments" rows="7" cols="1"></textarea></p>
<input type="submit" name="submit" class="button" value="Submit" />
</fieldset>
</form>
而且里面contact.php
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$service = $_POST['service'];
$comments = $_POST['comments'];
$header='From: '.$email."\r\n";
$header.='Content-Type: text/plain; charset=utf-8';
$msg='Message from: '.$name."\r\n";
$msg.='Email: '.$email."\r\n";
$msg.='Tel: '.$tel."\r\n";
$msg.='Interested in: '.$service."\r\n";
$msg.='Message: '.$comments."\r\n";
$msg.='Sent '.date("d/m/Y",time());
$msg.=utf8_decode('');
$to = '[email protected], [email protected], [email protected]';
$subject = 'Contact from website';
mail($to,$subject,$msg,$header);
}
header("Location: contact.html");
?>
我不知道需要什么样的变化对于插件使用PHP邮件功能。我很感激,如果有人可以看看,并帮我弄清楚这一点。提前致谢!
你不应该在'submitHandler()'中做[something](http://docs.jquery.com/Plugins/Validation/validate#toptions)吗? – jprofitt 2012-01-09 20:49:53
由于jQuery和PHP是完全无关的,所以很有可能会陷入低谷。我会先检查一下你的控制台日志,看看是否有错误 - 哪个btw会以某种方式出现,即使它不明显......就像人为错误(请参阅jprofitt的评论)。除此之外,我当然希望你真的没有在你的实际站点上的脚本标记之外准备好你的文档。 – 2012-01-09 20:51:03
谢谢,我想知道downvote :)我会考虑你的两个建议。是的,js部分位于文档头部的脚本标签内部,我在这里输入的速度非常快。 – brunn 2012-01-09 21:04:13