I'm having a problem to make this little form of this site run it is sending the email on the console it gives this error:
Line2code:
$("#submit_btn").click(function()...
follow my code: HTML:
<form id="form-elements" onSubmit="return false" class="form-inline text-center">
<div class="row">
<div class="col-md-12 center">
<div id="result"></div>
</div>
</div>
<div class="form-group">
<input type="email" class="form-control email-input" placeholder="Digite seu e-mail" name="email"
id="email" required>
<div id="gif" class="text-center" ></div>
</div>
<button type="submit" class="btn btn-primary button-send" id="submit_btn">Quero anunciar meu serviço</button>
</form>
JS:
//Contact Us
$("#submit_btn").click(function() {
//get input field values
var user_email = $('input[name=email]').val();
//simple validation at client's end
var post_data, output;
var proceed = true;
if(user_email==""){
proceed = false;
}
//everything looks good! proceed...
if(proceed)
{
//data to be sent to server
post_data = {'userEmail':user_email};
//Ajax post data to server
$("#gif").html('<img src="http://dev.cloudcell.co.uk/bin/loading.gif">');$.post('contact.php',post_data,function(response){//loadjsondatafromserverandoutputmessageif(response.type=='error'){output='<divclass="alert-danger" style="padding:10px; margin-bottom:25px;">'+response.text+'</div>';
}else{
output = '<div class="alert-success" style="padding:10px; margin-bottom:25px;">'+response.text+'</div>';
$("#gif").hide();
//reset values in all input fields
$('#form-elements input').val('');
}
$("#result").hide().html(output).slideDown();
}, 'json');
}
});
//reset previously set border colors and hide all message on .keyup()
$("#form-elements input, #form-elements").keyup(function() {
$("#result").slideUp();
});
PHP:
<?php
if($_POST)
{
$to_Email = "[email protected]"; //Replace with recipient email address
$subject = 'Contato - Página Konectah'; //Subject line for emails
//check if its an ajax request, exit if not
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
//exit script outputting json data
$output = json_encode(
array(
'type'=>'error',
'text' => 'Request must come from Ajax'
));
die($output);
}
//check $_POST vars are set, exit if any missing
if(!isset($_POST["userEmail"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Os campos de entrada estão vazios! '));
die($output);
}
//Sanitize input data using PHP filter_var().
$user_Email = filter_var($_POST["userEmail"], FILTER_SANITIZE_EMAIL);
//additional php validation
if(!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
{
$output = json_encode(array('type'=>'error', 'text' => 'Por favor ultilize um e-mail válido'));
die($output);
}
$message_Body .= "<strong>Email: </strong>". $user_Email ."<br>";
$headers = "From: " . strip_tags($user_Email) . "\r\n";
$headers .= "Reply-To: ". strip_tags($user_Email) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//proceed with PHP email.
$headers = 'From: '.$user_Email.'' . "\r\n" .
'Reply-To: '.$user_Email.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion(). "\r\n" .
'Content-type: text/html';
$sentMail = @mail($to_Email, $subject, $message_Body, $headers);
if(!$sentMail)
{
$output = json_encode(array('type'=>'error', 'text' => 'Ocorreu um erro tente novamente'));
die($output);
}else{
$output = json_encode(array('type'=>'message', 'text' =>' Obrigado por sua inscrição retornaremos em breve'));
die($output);
}
}
?>