I'm trying to submit my contact form, send the data in an email with PHP, stay on index.html and open a bootstrap modal with a "Thank you" message.
All the other examples I've seen that might do this have used AJAX. BUT I'd like to do it through PHP alone as my AJAX knowledge is non existent. Does anyone know if its even possible? and if so, how?
I've only included the last part that makes sure I return to index.html or displays the errors from the form submission
PHP from contact.php.
if(!$mail->Send()){
echo "Message could not be sent.";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
print '<meta http-equiv="refresh" content="0; url=index.html" />';
echo "<script>$('#myModal').modal('show')</script>";
HTML
<form id='contactus' action='contact.php' enctype="multipart/form-data" method='post'>
<fieldset>
<legend>Contact us</legend>
<div class='container'>
<label for='email' >Name*:</label><br/>
<input type="text" id="name" name="name" required /><br>
<label for='email' >Phone*:</label><br/>
<input type="text" id="phone" name="phone" required /><br>
<label for='email' >Email*:</label><br/>
<input type='text' name='email' id='email' required/><br/>
<label for='message' >Message:</label><br/>
<textarea rows="10" cols="50" name='message' id='message'></textarea>
<!-- MAX_FILE_SIZE must precede the file input field -->
<br>
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input id="file" name="image" type="file" />
<input type='submit' name='Submit' value='Submit' />
</div>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Thanks!</h4>
</div>
<div class="modal-body">
<p>Thank you for your message!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>