我是網絡開發新手,我需要此聯繫表單的幫助。 我正在使用引導程序模板。我不知道聯繫表格有什麼問題
張貼錯誤對不起球員,我是新來的,我我有點困惑的發佈和編輯。
這是我的PHP代碼:
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message']);
// $human = intval($_POST['human']);
$from = 'Demo Contact Form';
$to = '[email protected]';
$subject = 'Message from Contact Demo ';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
//Check if simple anti-bot test is correct
//if ($human !== 5) {
// $errHuman = 'Your anti-spam is incorrect';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
JS代碼
function contactForm(){
$('.btn-submit').on('click',function(e){
var $this = $(this);
e.preventDefault();
$.ajax({
url : 'contact.php',
type : 'POST',
data : $this.closest('.contact-form').serialize(),
success : function(data){
if ($(data).is('.send-true')){
$this.addClass('loading').delay(650).queue(function(){
$this.addClass('success').addClass('loaded').dequeue();
});
} else {
$this.addClass('error');
}
$this.delay(500).queue(function(){
$this.removeClass('loaded').removeClass('loading').dequeue();
});
$this.delay(400).queue(function(){
if ($(data).is('.send-true')){
$this.removeClass('success').closest('.contact-form').trigger('reset');
} else {
$this.removeClass('error');
}
$this.dequeue();
});
}
});
});
}
LOL ....你的PHP代碼實際上是JS代碼.....發表您的PHP代碼,請...'contact.php' – Umair
的代碼是什麼在控制檯中的錯誤? –
或者試試'success:function(data){console.log(data)'並查看控制檯中的內容? – Umair