Hi folks! I have been using relatively clean and simple PHP contact forms for quite some time now. They fit my needs and are easy to work with. However, after submitting the message, it takes me to a gray screen with the nothing but text I programmed it to echo. It isn't an error or bug, but it's an ugly redirect and does not look professional.
I would like to learn how to work with this in one of two ways: either submit the message without leaving the contact page, or add a redirect of some sort.
This is the contact.php file I use. If anyone has input on how to do this, it'd be greatly appreciated!!
<?phpfunction spamcheck($field) { //filter_var() sanitizes the e-mail //address using FILTER_SANITIZE_EMAIL $field=filter_var($field, FILTER_SANITIZE_EMAIL); //filter_var() validates the e-mail //address using FILTER_VALIDATE_EMAIL if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } }if (isset($_REQUEST['email'])) {//if "email" is filled out, proceed //check if the email address is invalid $mailcheck = spamcheck($_REQUEST['email']); if ($mailcheck==FALSE) { echo "Invalid input. Please enter a valid email address."; } else {//send email $name = $_POST['name'] ; $email = $_POST['email'] ; $message = $_POST['message'] ; $totalmessage = " Name: $name n Details: $message n"; mail("email@email.com", "Email: $email", $totalmessage, "From: $email" ); echo "Thank you for contacting me. I'll get back with you ASAP."; } }else { //if "email" is not filled out, display the form?> <form method="post" action="contact.php"> <div class="row half"> <div class="6u"><input type="text" name="name" placeholder="Name" /></div> <div class="6u"><input type="email" name="email" placeholder="Email" /></div> </div> <div class="row half"> <div class="12u"><textarea name="message" placeholder="Message" rows="6"></textarea></div> </div> <div class="row"> <div class="12u"> <ul class="actions"> <li><input type="submit" value="Send Message" name="submit" /></li> </ul> </div> </div> </form><?php}?>