Reputation: 11
I have a basic contact form on my site that works fine. When submitted though it opens a blank page with "Thank you" ... I would like to potentially open a styled web page that says "submitted successfully" displays for around 3 seconds, then reverts back to the main page. I'm quite new to web design and especially PHP so if anyone could give any tips that would be great. I have put the PHP code below:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent = "From: $name \r\n Message: $message";
$recipient = "[email protected]";
$mailheader = "From: $email \r\n";
mail($recipient, $message, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
Upvotes: 0
Views: 155
Reputation: 6679
Although Wayne Whitty's answer is right, I do have another note/answer:
To redirect after 3 seconds use this:
<meta http-equiv="refresh" content="3;url=http://YOURPAGE.php">
I see you are redirecting from a different page but that is pretty useless. You could also just put this in the main page and use this to only redirect after submitting. (The form is an example, I dont know how your form looks like)
<form action="register.php" method="post">
Username <input type="text" name="name">
Password <input type="text" name="email">
Message <input type="text" name="message">
<input name="register" type="submit" value="Register">
</form>
<?php
if (isset($_POST['name'])) {
echo'<meta http-equiv="refresh" content="3;url=http://YOURPAGE.php">';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent = "From: $name \r\n Message: $message";
$recipient = "[email protected]";
$mailheader = "From: $email \r\n";
mail($recipient, $message, $formcontent, $mailheader) or die("Error!");
echo "submitted successfully";
}
?>
Also just replace: echo "Thank You!";
with echo "submitted successfully";
Upvotes: 0
Reputation: 19879
Try:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent = "From: $name \r\n Message: $message";
$recipient = "[email protected]";
$mailheader = "From: $email \r\n";
mail($recipient, $message, $formcontent, $mailheader) or die("Error!");
?><!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="3; url=http://mysite.com/contact.php">
</head>
<body>
<p>Submitted successfully</p>
</body>
</html>
If the email is sent, the message "Submitted successfully" will show. Three seconds later, it will redirect to http://mysite.com/contact.php
. Change http://mysite.com/contact.php
to the URL you want to return to.
Upvotes: 1