1

How can I make php redirect after email message was sent?

Azrath's Avatar Azrath6/19/17 7:35 am
1 emeralds 410 1
7/5/2017 4:05 pm
SupremeMortal's Avatar SupremeMortal
So I am trying to make redirection after submitting the form to the home page. Fine, it works BUT there is one problem. The message is not displayed as user presses "Submit" button but is instantly redirected to the Home page. How can I make it so users first recieve "Thank you" message and than are redirected to the Home page?

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'vladozabunov@gmail.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: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_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.');
window.location = 'contact_page.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to gordon@template-help.com');
window.location = 'contact_page.html';
</script>
<?php
}
header('Location: https://saprs.000webhostapp.com/index.html');
?>
Posted by Azrath's Avatar
Azrath
Level 24 : Expert Button Pusher
65

Create an account or sign in to comment.

1

1
07/05/2017 4:05 pm
Level 22 : Expert Geek
SupremeMortal
SupremeMortal's Avatar
This will redirect a user after 3 seconds to http://example.com
Place it in the head:
<meta http-equiv="refresh" content="3;url=http://example.com" />
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome