I am new to php and bootstrap, so go easy on me.
I have a HTML5 template that uses Bootstrap 3.3.4 that I have done a bunch of work on customizing it to our needs. There is a contact form on the html page that uses HTML5 validation and a sendmail.php page to send a message to us. I read up a bit on php and managed to configure it to send successfully when installed on our server, however right now the confirmation is being redirected to a new page once submit is clicked. I would like to modify it so that the echo "alert" shows as a bootstrap alert (green or red) on the same html5 page above or below the contact form rather than opening a new page. Through my searching I found the bootstrap alert code (lines 3-5) for the html side and added to my code below:
<div class="contact-form default-form">
<form method="post" action="sendmail.php">
<div class="alert alert-success hide"></div>
<br style="clear:both">
<div class="alert alert-danger hide"></div>
<div class="form-group">
<input type="text" name="name" value="" placeholder="Name *" required></div>
<div class="form-group">
<input type="email" name="email" value="" placeholder="Email *" required></div>
<div class="form-group">
<input type="text" name="subject" value="" placeholder="Subject*" required></div>
<div class="form-group">
<textarea name="message" placeholder="Message *" required></textarea>
</div>
<button type="submit" class="theme-btn btn-style-two">Send Message</button>
</form>
</div>
</div>
but I am not sure how to have the sendmail.php post the messages to the html file. Here is my sendmail.php file:
<?php
//we need to get our variables first
$email_to = 'sales@*****************.ca'; //the address to which the email will be sent
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
/*the $header variable is for the additional headers in the mail function,
we are asigning 2 values, first one is FROM and the second one is REPLY-TO.
That way when we want to reply the email gmail(or yahoo or hotmail...) will know
who are we replying to. */
$headers = 'From: '. $name . '<' . $email . '>' . "\r\n";
$headers .= "Reply-To: $email\r\n";
if(mail($email_to, $subject, $message, $headers)){
echo 'Thanks for your message. Someone will be in touch soon!'; // we are sending this text to the ajax request telling it that the mail is sent..
}else{
echo 'Message failed to send. Please get in touch with us via another contact option or try again later.';// ... or this one to tell it that it wasn't sent
}
?>
Any help would be appreciated!