This contact.php will process the data and send it to my email. I want to achieve this effect, when user submit the form correctly, it will display a alert, and then redirect the page to : thankyou.html.
When there is some error, it will display another alert, and then redirect the page to error.html.
Whether below code can get this done? Thank you for your help or suggestion.
<?php
$field_firstname = $_POST['cf_firstname'];
$field_lastname = $_POST['cf_lastname'];
$field_emailaddress= $_POST['cf_emailaddress'];
$field_telepohone = $_POST['cf_telephone'];
$field_country = $_POST['cf_country'];
$field_business = $_POST['cf_business'];
$field_comments = $_POST['cf_comments'];
$mail_to = 'someone@somewhere.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$cf_email."\r\n";
$headers .= 'Reply-To: '.$cf_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
setTimeout("window.location= 'thankyou.html', 1250);
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please check the items required');
setTimeout("window.location= 'error.html', 1250);
</script>
<?php
}
?>