January 4, 201214 yr Hello, im just starting out with php so bare with me! Im making the contact form side of my site, When clicking submit, it loads mailer.php which displays: echo "Data has been submitted to $to!"; However... i wish it to redirect back onto my website after say 5 seconds. Is this possible with php? Ive tried adding a sleep into it but it doesnt load the mailer.php it just waits. I added it like so: <?php if(isset($_POST['submit'])) { $to = "craiglovelock54@hotmail.co.uk"; $subject = "Form Tutorial"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message"; echo "Data has been submitted to $to!"; mail($to, $subject, $body); sleep(10);//seconds to wait.. header("Location:http://www.vinylpenguin.co.uk/page.php"); } else { echo "blarg!"; } ?> I expected it to load the page then run the sleep part but it doesnt. Any help? Edited January 4, 201214 yr by Lovelock
January 4, 201214 yr Hi Lovelock I think the redirection isn't occuring as the php headers have already been sent and an error is being generated. Have you got php error reporting turned on? If not I would advise you to turn it on http://php.about.com/od/troubleshooting/qt/php_error_reporting.htm Your idea is fine - your code just needs a few tweaks. A good example of a basic form with a similar problem can be found here: http://stackoverflow.com/questions/4943768/simple-php-form-redirect The header example produced by blasteralfred is equivalent to your code sleep(10);//seconds to wait.. header("Location:http://www.vinylpenguin.co.uk/page.php"); Paul Edited January 4, 201214 yr by paulb
January 4, 201214 yr Mind if I say, thank you for the sleep() function. I didn't knew of that function before and indeed it must be your location, all seems to be fine. Edited January 4, 201214 yr by kensha
January 4, 201214 yr Author Hi Lovelock I think the redirection isn't occuring as the php headers have already been sent and an error is being generated. Have you got php error reporting turned on? If not I would advise you to turn it onhttp://php.about.com/od/troubleshooting/qt/php_error_reporting.htm Your idea is fine - your code just needs a few tweaks. A good example of a basic form with a similar problem can be found here:http://stackoverflow.com/questions/4943768/simple-php-form-redirect The header example produced by blasteralfred is equivalent to your code sleep(10);//seconds to wait.. header("Location:http://www.vinylpenguin.co.uk/page.php");Paul Hello, it redirects, but it doesnt show the php page. I still want it to go to the php page but then redirect back to main site. If that makes sense. So without the redirection, it goes to a blank page with the echo output of "Your message is sent bla" I will style this page to look like the main page but want it as a confirmation process. With the redirection where it is, on clicking submit / send etc, it waits 10 seconds then goes to main page. Missing out the php page EDIT: Sorted with this instead of the sleep: header("Refresh: 3; url=\"http://www.vinylpenguin.co.uk/page.php\""); Edited January 4, 201214 yr by Lovelock
Create an account or sign in to comment