我正在使用jquery验证插件来验证我的网络中的联系表单,但我不知道如何将验证后的表单字段传递给php文件以将其发送到我的peronal电子邮件。
这是我的js代码:
$('#contact-us').validate(
{
rules: {
contactName: {
minlength: 2,
required: true
},
email: {
required: true,
email: true
},
subject: {
minlength: 2,
required: true
},
comments: {
minlength: 2,
required: true
}
},
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
}); // end document.ready
我想我必须使用类似解决方案的东西,但我无法让它工作。
有人可以帮助我吗?提前致谢
您需要表单
的操作部分中的 php 表单,一旦表单经过验证,其脚本将运行。
示例联系表单 html 代码
<form method="post" action="submit.php" id="formwa">
<label for="name">Your Name</label>
<input type="text" name="name" id="name" placeholder="Your name here">
<label for="email">Email address</label>
<input type="email" name="email" id="email" placeholder="Enter email">
<button type="submit" class="btn btn-warning">Keep me Updated!</button>
</form>
对应提交.php代码
<?php
//$to = $_POST['to'] ;
$message = "Hi there, 'n You have a new visitor on your Website.'n'r The person's name is: ".$_POST['name']."'r'n'r'nAnd the person's Email id is: ".$_POST['email'];
$from = $_POST['email'];
$headers = "From: ".$_POST['email'];
mail( "you@yourdomain.com", "Subject Line for the Email", $message, $headers);
// mail( "another@yourdomain.com", "Carbon Copy: Subject Line", $message, $headers);
?>
我希望这能帮助你理解它。上面的代码缺乏验证,但好吧,你一直在进行验证本身。如果有更多的困惑,请多问。干杯
< form action="email.php" >
在表单操作页面中,您可以在那里获取可以发送电子邮件的值