本页底部的联系表单http://nmfnebbs.preview.infomaniak.website/ 不起作用,当我填写所有字段并单击按钮发送时,将显示错误消息,并且不会向我的电子邮件发送任何内容。 以下是联系表格的脚本:
var submitContact = $('#submit_contact'),
message = $('#msg');
submitContact.on('click', function(e){
e.preventDefault();
var $this = $(this);
$.ajax({
type: "POST",
url: 'contact.php',
dataType: 'json',
cache: false,
data: $('#contact-form').serialize(),
success: function(data) {
if(data.info !== 'error'){
$this.parents('form').find('input[type=text],textarea,select').filter(':visible').val('');
message.hide().removeClass('success').removeClass('error').addClass('success').html(data.msg).fadeIn('slow').delay(5000).fadeOut('slow');
} else {
message.hide().removeClass('success').removeClass('error').addClass('error').html(data.msg).fadeIn('slow').delay(5000).fadeOut('slow');
}
}
});
});
这是contact.php的内容(我的电子邮件地址除外)
/* ========================== Define variables ========================== */
#Your e-mail address
define("__TO__", "my email address");
#Message subject
define("__SUBJECT__", "IT-vip.com.tn");
#Success message
define('__SUCCESS_MESSAGE__', "Votre message a bien été envoyé");
#Error message
define('__ERROR_MESSAGE__', "Erreur, Votre message n'a pas été envoyé");
#Messege when one or more fields are empty
define('__MESSAGE_EMPTY_FILDS__', "Veuillez remplir tous les champs");
/* ======================== End Define variables ======================== */
//Send mail function
function send_mail($to,$subject,$message,$headers){
if(@mail($to,$subject,$message,$headers)){
echo json_encode(array('info' => 'success', 'msg' => __SUCCESS_MESSAGE__));
} else {
echo json_encode(array('info' => 'error', 'msg' => __ERROR_MESSAGE__));
}
}
//Check e-mail validation
function check_email($email){
if(!@eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
return false;
} else {
return true;
}
}
//Get post data
if(isset($_POST['name']) and isset($_POST['mail']) and isset($_POST['comment'])){
$name = $_POST['name'];
$mail = $_POST['mail'];
$website = $_POST['website'];
$comment = $_POST['comment'];
if($name == '') {
echo json_encode(array('info' => 'error', 'msg' => "Veuillez saisir votre nom"));
exit();
} else if($mail == '' or check_email($mail) == false){
echo json_encode(array('info' => 'error', 'msg' => "Veuillez saisir votre e-mail valide"));
exit();
} else if($comment == ''){
echo json_encode(array('info' => 'error', 'msg' => "Veuillez saisir votre message."));
exit();
} else {
//Send Mail
$to = __TO__;
$subject = __SUBJECT__ . ' ' . $name;
$message = '
<html>
<head>
<title>Mail from '. $name .'</title>
</head>
<body>
<table style="width: 500px; font-family: arial; font-size: 14px;" border="1">
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">Name:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $name .'</td>
</tr>
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">E-mail:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $mail .'</td>
</tr>
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">Website:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $website .'</td>
</tr>
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">Comment:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $comment .'</td>
</tr>
</table>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: ' . $mail . "\r\n";
send_mail($to,$subject,$message,$headers);
}
} else {
echo json_encode(array('info' => 'error', 'msg' => __MESSAGE_EMPTY_FILDS__));
}
?>