Wednesday, 18 September 2013

Create success message on php form submit

Create success message on php form submit

I'm trying to make a php mail form display a success message upon a
successful submit. I'm new to php and I'm not sure how to make this work.
As it sits now, after submit, the site just reloads at the top of the
page. I'd like it to refresh at the contact div and display a success
message.
Contact div html:
<div class="contact-wrapper" >
<div class="contact">
<div class="contact-left" id="contact">
<?php
if (isset($_REQUEST['email'])) {
echo "Thank you for your message.";
}
$mail_form = include('php/mail_form.php'); ?>
</div> <!-- end div contact -->
Contact from PHP:
<?php
function 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";
}
else
{//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("idc615@gmail.com", "Subject: $subject",
$message, "From: $email" );
header("location: index.php");
}
}
?>

No comments:

Post a Comment