我有一个基本的联系表格,由于某种原因它不会发送任何想法:http ://redline-interiors.com/contact.html
联系人.html
<ul class="contactform">
<li><label>Name </label><input type="text" id="namefield" name="contact_name" class="form_field contactInput required" /></li>
<li><label>Subject </label><input type="text" id="subjectfield" name="contact_subject" class="form_field contactInput required" /></li>
<li><label>Email </label><input type="text" id="emailfield" name="contact_email" class="form_field contactInput required email" /></li>
<li><label>Message </label><textarea id="messagefield" name="contact_message " class="contactInput required"></textarea></li>
<li><button id="sendMessage" class="btn"><i class="icon-mail-2"></i> Send Message</button></li>
</ul>
主处理器.php
include_once (dirname(dirname(__FILE__)).'/CONFIG.php');
//Initial response is NULL
$response = null;
//Initialize appropriate action and return as HTML response
if (isset($_POST["action"])) {
$action = $_POST["action"];
switch ($action) {
case "Initialize": {
$mainData = array();
include_once (dirname(dirname(__FILE__)).'/php/classes/class__twitter.php');
$twitter = new LordWEBTweet();
$twitts = $twitter->GetTweets($twitter_name, 3);
$mainData["Twitts"] = $twitts;
$mainData["Start_Date"] = $start_date;
$response = $mainData;
}
break;
case "SignUp": {
if (isset($_POST["email"]) && !empty($_POST["email"])) {
$subscriberEmail = $_POST["email"];
include_once (dirname(dirname(__FILE__)).'/php/classes/class__mail.php');
$messageText = 'You have new subscriber for your site.<br /><br />This is the subscribed email address<br />====================================<br />' . $subscriberEmail;
$mail = new LordWEBMail();
$response = ($mail->SendEmail($messageText, $signUpNotificationSubject, $signUpEmail, $email)) ? "Message Sent" : "Sending Message Failed";
} else {
$response = "Sending Message Failed";
}
}
break;
case "SendMessage": {
if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["subject"]) && isset($_POST["message"])
&& !empty($_POST["name"]) && !empty($_POST["email"]) && !empty($_POST["subject"]) && !empty($_POST["message"])) {
include("classes/class__mail.php");
$mail = new LordWEBMail();
$response = ($mail->SendEmail($_POST["message"], $_POST["subject"], $_POST["email"], $email)) ? "Message Sent" : "Sending Message Failed";
} else {
$response = "Sending Message Failed";
}
}
break;
default: {
$response = "Invalid action is set! Action is: " . $action;
}
}
}
if (isset($response) && !empty($response) && !is_null($response)) {
echo '{"ResponseData":' . json_encode($response) . '}';
}
?>
main.js
$('#sendMessage').click(function(){
if(validateInput()){
sendMail();
}else
{
alert('Please fill all fields to send us message.');
}
});
var validateInput = function(){
var isValid = true;
$('input, textarea').each(function(){
if($(this).hasClass('required'))
{
if($(this).val()!=''){
if($(this).hasClass('email'))
{
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test($(this).val())){
isValid = false;
alert('Your email is not in valid format');
}
}
}else
{
isValid = false;
}
}
});
return isValid;
};
var resetInput = function(){
$('input, textarea').each(function() {
$(this).val('').text('');
});
};
var sendMail = function(){
var params = {
'action' : 'SendMessage',
'name' : $('[name=contact_name]').val(),
'email' : $('[name=contact_email]').val(),
'subject' : $('[name=contact_subject]').val(),
'message' : $('[name=contact_message]').val()
};
$.ajax({
type: "POST",
url: "php/mainHandler.php",
data: params,
success: function(response){
if(response){
var responseObj = jQuery.parseJSON(response);
if(responseObj.ResponseData)
$('label.sendingStatus').text(responseObj.ResponseData);
showMessage('Your message was sent. Thank you!');
}
resetInput();
$('#sendMail').removeAttr('disabled');
},
error: function (xhr, ajaxOptions, thrownError){
//xhr.status : 404, 303, 501...
var error = null;
switch(xhr.status)
{
case "301":
error = "Redirection Error!";
break;
case "307":
error = "Error, temporary server redirection!";
break;
case "400":
error = "Bad request!";
break;
case "404":
error = "Page not found!";
break;
case "500":
error = "Server is currently unavailable!";
break;
default:
error ="Unespected error, please try again later.";
}
if(error){
$('label.sendingStatus').text(error);
}
}
});
};
编辑:格式化代码以便于理解。感谢任何回答的人。删除链接,因为它是不允许的,并且由于死胡同而没有帮助。