I am trying to send email with php using AJAX. When I click the button nothing happens. No error and no mail in my mailbox. Here is my code:
index.php:
<div>
<div class="col-md-offset-4 col-md-4 col-lg-4">
<center>
<form method="post">
<section id="left">
<label for="form_email">Email</label>
<input name="form_email" id="form_email" type="email" >
</section>
<section id="right">
<label for="form_msg">Message</label>
<textarea name="form_msg" id="form_msg"></textarea>
<button id="submit" class="button" name="submit" type="button">Send</button>
</section>
</form>
</center>
</div>
</div>
Here is javascript in index.php:
<script>
$("#submit").click(function(){
var data = {
email: $("#form_email").val(),
message: $("#form_msg").val(),
};
$.ajax({
type: "POST",
url: "mail.php",
data: data,
success: function(){
$('.success').fadeIn(1000);
}
});
});
</script>
External mail.php:
<?php
$email = $_POST['form_email'];
$subject = "AdrTürkiye Veri Giriş Ekranı";
$message = $_POST['form_msg'];
@mail($email, $subject, $message);
?>