PHP 邮件功能不适用于 jQuery 验证插件
我有一个联系表格,效果很好。不过,我正在尝试使用 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 邮件功能。如果有人能看一下并帮助我解决这个问题,我将不胜感激。提前致谢!
I have a contact form that works fine. However I'm trying to use the jQuery validation plugin to check that there are no empty fields left before submitting, but when I add the plugin I no longer receive any emails.
The code is as follows:
Inside 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>
And inside 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");
?>
I don't know what changes are required for the plugin to work with PHP mail function. I'd appreciate if someone can take a look and help me figure this out. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然 PHP 没有任何关系。我在submitHandler函数上缺少
form.submit();
。感谢 jprofitt 和 Kai Qing。Certainly PHP had nothing to do. I was missing
form.submit();
on the submitHandler function. Thanks to jprofitt and Kai Qing.