// Java script
var form = $('#main-contact-form');
form.submit(function(event){
event.preventDefault();
var form_status = $('<div class="form_status"></div>');
var $form = $( this );
$.ajax({
type: 'POST',
url: "sendemail.php",
data:{
Name:$form.find( "input[name='name']" ).val() ,
Subject:$form.find( "input[name='subject']" ).val() ,
Email:$form.find( "input[name='email']" ).val() ,
message: $form.find("textarea[name=message]").val(),
},
beforeSend: function(){
form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn() );
}
}).done(function(data){
form_status.html('<p class="text-success">Thank you for contact us. As early as possible we will contact you</p>').delay(3000).fadeOut();
});
});
I'm running the form on free plan on 000webhost (trying on herokuapp right now), they say that they support mail function. Php is separated in a different file called sendemail.php, I replace my email in php file but I can't receive any emails, what can be the issue? Any answers with code would be helpful
<!--Html form -->
<form id="main-contact-form" name="contact-form" method="post" action="#">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Name" required>
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email" required>
</div>
<div class="form-group">
<input type="text" name="subject" class="form-control" placeholder="Subject" required>
</div>
<div class="form-group">
<textarea name="message" class="form-control" rows="8" placeholder="Message" required></textarea>
</div>
<button type="submit" class="btn btn-primary">Send Message</button>
</form>
sendemail.php file
$name = @trim(stripslashes($_POST['name']));
$from = @trim(stripslashes($_POST['email']));
$subject = @trim(stripslashes($_POST['subject']));
$message = @trim(stripslashes($_POST['message']));
$to = 'email@live.com';//replace with your email
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $message, $headers);
die;