form não envia email
Boa tarde, estou tentando fazer um formulário enviar e-mail mas não dá certo.
Quando preencho os campos diz que o formulário foi enviado, mas não recebo nem
no spam.
Podem ver o formulário aqui http://www.daisybez.com.br/kappe/contact.html
Se alguém puder dar uma ajuda, agradeço desde já.
Segue codigo:
contact.html
<form id="contact-form">
<h1>Envie sua mensagem para nós<span class="submit-area">
<input name="submit" type="submit" class="main-button" id="submit_contact" value="Enviar">
</span></h1>
<div class="text-fields">
<div class="float-input">
<input name="nome" id="nome" type="text" placeholder="Nome">
<span><i class="fa fa-user"></i></span>
</div>
<div class="float-input">
<input name="mail" id="mail" type="text" placeholder="e-mail">
<span><i class="fa fa-envelope-o"></i></span>
</div>
<div class="float-input">
<input name="assunto" id="assunto" type="text" placeholder="assunto">
<span><i class="fa fa-link"></i></span>
</div>
</div>
<div class="submit-area">
<textarea name="comment" id="comment" placeholder="Message"></textarea>
<div id="msg" class="message"></div>
</div>
</form>
**contact.php**
<?php
/* ========================== Define variables ========================== */
#Your e-mail address
define("__TO__", "jeweber@gmail.com");
#Message subject
define("__SUBJECT__", "examples.com = From:");
#Success message
define('__SUCCESS_MESSAGE__', "Your message has been sent. Thank you!");
#Error message
define('__ERROR_MESSAGE__', "Error, your message hasn't been sent");
#Messege when one or more fields are empty
define('__MESSAGE_EMPTY_FILDS__', "Please fill out all fields");
/* ======================== 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['nome']) and isset($_POST['mail']) and isset($_POST['comment'])){
$name = $_POST['nome'];
$mail = $_POST['mail'];
$website = $_POST['assunto'];
$comment = $_POST['comment'];
if($name == '') {
echo json_encode(array('info' => 'error', 'msg' => "Please enter your name."));
exit();
} else if($mail == '' or check_email($mail) == false){
echo json_encode(array('info' => 'error', 'msg' => "Please enter valid e-mail."));
exit();
} else if($comment == ''){
echo json_encode(array('info' => 'error', 'msg' => "Please enter your 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;">'. $nome .'</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;">'. $assunto .'</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__));
}
?>
**script.js**
/*
/ ---------------------------------------------------------------------- /
/* Contact Form
/ ---------------------------------------------------------------------- /
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');
}
}
});
});Discussão (16)
Carregando comentários...