Got an issue with this mail php script that is not sending the mail, I have tested the server with a simple php mail test script which works fine so that leads me to believe it's something to do with this coding.
HTML
<form id="contact-form" class="row style1" action="#" method="post">
<div class="col-xs-12 col-sm-4">
<div class="form-group">
<input name="name" type="text" id="name" placeholder="Your name" required />
</div>
<div class="form-group">
<input name="number" type="text" id="number" placeholder="Your number" required />
</div>
<div class="form-group">
<input name="email" type="email" id="email" placeholder="Your e-mail" required />
</div>
</div>
<div class="col-xs-12 col-sm-8">
<textarea name="message" rows="4" class="h130" id="message" placeholder="Write your message..." required></textarea>
</div>
<div class="clear"></div>
<div class="col-md-9"><p>* When do you want to <strong>reserve the cottage</strong>, please write date, time and number of guests into your message.</p><p><a href="terms.html">Terms & Conditions/Privacy</a></p></div>
<div class="col-md-3 right">
<input class="submit btn" type="submit" value="Send a message" />
<input class="modal btn hidden" type="button" value="Send a message" name="" data-toggle="modal" data-target="#modalBox" />
</div>
<!-- Modal window -->
<div class="modal fade bs-modal-md" id="modalBox" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Contact form</h4>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn right" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</form>
PHP
<?php
//******** Email settings ********//
//your email
$email_to = "myemail@mydomain.com";
//subject of email
$email_subject = "Message from website";
//message after success send mail
$email_send = "<div class='alert alert-success'>
<strong>Contact form was sent successfully.</strong>
<br/>Thank you for contacting us. We will be in touch with you very soon.</div>";
if($_POST) {
//******** Email data ********//
$cust_name = $_POST['name'];
$cust_number = $_POST['number'];
$cust_email = $_POST['email'];
$cust_message = $_POST['message'];
$header = "From:" . $cust_email . "\r\n";
$header .= 'MIME-Version: 1.0' ."\r\n";
$header .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";
$body = "<strong>Customer email:</strong> " . $cust_email . "<br/>";
$body .= "<strong>Customer number:</strong> " . $cust_number . "<br/>";
$body .= "<strong>Customer name:</strong> " . $cust_name . "<br/>";
$body .= "<strong>Message:</strong> " . $cust_message;
if($cust_name && $cust_number && $cust_email && mail($email_to, $email_subject, $body, $header)) {
echo $email_send;
echo '<script>$("#contact-form").each(function(){
this.reset();
});
</script>';
} else {
echo "<div class='alert alert-warning'><strong>Error sending mail. Please fill the contact form correctly or contact website administrator.</strong></div>";
}
}
?>
JS
/* Contact Form Script */
$("#contact-form").submit(function( event ) {
event.preventDefault();
$(".modal.btn").click();
$.ajax({
type: "POST",
url: "send-contact-form.php",
data: $('#contact-form').serialize()
}).done(function(data) {
$(".modal-body").html(data);
});
});
});
When sending email everything works fine, i.e. the modal window pops up saying email sent etc. Probably there is just no email being received.
Thanks, Paul