ultratek Posted October 3, 2008 Share Posted October 3, 2008 i want to have this script redirect from -Mail has been sent successfully- after 3 secs back to home page how could i do this? scipt: <?php ini_set("SMTP","bosmail.nt.com"); $name = $_POST['name']; $phone = $_POST['phone']; $email = $_POST['email']; $subject = $_POST['subject']; $comments = $_POST['comments']; if (isset($_POST['submit'])) { $errors = array(); if (empty($_POST['name'])) { $errors[] = 'You forgot to enter your name.'; } if (empty($_POST['phone'])) { $errors[] = 'You forgot to enter your phone number.'; } if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email.'; } if (empty($_POST['subject'])) { $errors[] = 'You forgot to enter the subject.'; } if (empty($_POST['comments'])) { $errors[] = 'You forgot to enter comments.'; } } else { } if (empty($errors)) { $name = $name; //senders name $email = $email; //senders e-mail adress //$recipient = "atomicstructure@gmail.com"; //recipient $recipient = "copiman@gmail.com"; //recipient //$recipient = "ravimrk_diya@yahoo.com"; //recipient $comments = "$comments...\n\n".$phone; $subject = $subject; //subject $header = "From: ". $name . " <" . $email . ">\r\n"; //optional headerfields mail($recipient, $subject, $comments, $header); //mail command echo "Mail has been sent successfully."; } else { echo 'The following error(s) occurred:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo 'Please go back and try again.<br />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/126895-solved-redirect/ Share on other sites More sharing options...
Andy17 Posted October 3, 2008 Share Posted October 3, 2008 <?php header('Refresh: 3; url=index.html'); ?> OR <?php sleep(3); // Seconds until redirecting header("Location:http://www.domain.com"); ?> I recommend the first one. Quote Link to comment https://forums.phpfreaks.com/topic/126895-solved-redirect/#findComment-656329 Share on other sites More sharing options...
ultratek Posted October 3, 2008 Author Share Posted October 3, 2008 thank you... i used the first one for some reason it did not recognize the sleep() it just instantly redirected Quote Link to comment https://forums.phpfreaks.com/topic/126895-solved-redirect/#findComment-656342 Share on other sites More sharing options...
Maq Posted October 3, 2008 Share Posted October 3, 2008 Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/126895-solved-redirect/#findComment-656359 Share on other sites More sharing options...
ultratek Posted October 3, 2008 Author Share Posted October 3, 2008 <?php ini_set("SMTP","bosmail.nt.com"); $name = $_POST['name']; $phone = $_POST['phone']; $email = $_POST['email']; $subject = $_POST['subject']; $comments = $_POST['comments']; if (isset($_POST['submit'])) { $errors = array(); if (empty($_POST['name'])) { $errors[] = 'You forgot to enter your name.'; } if (empty($_POST['phone'])) { $errors[] = 'You forgot to enter your phone number.'; } if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email.'; } if (empty($_POST['subject'])) { $errors[] = 'You forgot to enter the subject.'; } if (empty($_POST['comments'])) { $errors[] = 'You forgot to enter comments.'; } } else { } if (empty($errors)) { $name = $name; //senders name $email = $email; //senders e-mail adress //$recipient = "atomicstructure@gmail.com"; //recipient $recipient = "copiman@gmail.com"; //recipient //$recipient = "ravimrk_diya@yahoo.com"; //recipient $comments = "$comments...\n\n".$phone; $subject = $subject; //subject $header = "From: ". $name . " <" . $email . ">\r\n"; //optional headerfields mail($recipient, $subject, $comments, $header); //mail command echo "Mail has been sent successfully.You are being redirected home."; header('Refresh: 3; url=index.html'); } else { echo 'The following error(s) occurred:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo 'Please go back and try again.<br />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/126895-solved-redirect/#findComment-656431 Share on other sites More sharing options...
Andy17 Posted October 3, 2008 Share Posted October 3, 2008 thank you... i used the first one for some reason it did not recognize the sleep() it just instantly redirected Hmm, worked for me. However, I like the first one better too. Quote Link to comment https://forums.phpfreaks.com/topic/126895-solved-redirect/#findComment-656446 Share on other sites More sharing options...
JD* Posted October 3, 2008 Share Posted October 3, 2008 Sleep does not always work properly...I find in my code it will pause ALL execution of code for the number of seconds defined, then continue on. What you can, instead, is this: echo '<meta http-equiv="Refresh" content="10">'; and replace the "10" with your duration (in seconds) -- Edit -- Sorry, I didn't see that the above code has no HTML as part of it...my tip works if you have other HTML in the page and code is going to be executed (such as display a message on the same page, then redirect for a logout or something similar). Quote Link to comment https://forums.phpfreaks.com/topic/126895-solved-redirect/#findComment-656477 Share on other sites More sharing options...
Maq Posted October 3, 2008 Share Posted October 3, 2008 Sleep does not always work properly...I find in my code it will pause ALL execution of code for the number of seconds defined, then continue on. That's what sleep() is supposed to do. Quote Link to comment https://forums.phpfreaks.com/topic/126895-solved-redirect/#findComment-656484 Share on other sites More sharing options...
ultratek Posted October 3, 2008 Author Share Posted October 3, 2008 thanks for the tip jd =) Quote Link to comment https://forums.phpfreaks.com/topic/126895-solved-redirect/#findComment-656492 Share on other sites More sharing options...
JD* Posted October 4, 2008 Share Posted October 4, 2008 Sleep does not always work properly...I find in my code it will pause ALL execution of code for the number of seconds defined, then continue on. That's what sleep() is supposed to do. Yes, but I find that many people on here suggest using it as something that will do this: Processing code..... [tell php to sleep, so it looks like we're loading while playing an animated gif] Finished processing Just warning that sleep does not do that...I don't think that was the intention of the people above, but just an FYI Quote Link to comment https://forums.phpfreaks.com/topic/126895-solved-redirect/#findComment-656984 Share on other sites More sharing options...
Maq Posted October 4, 2008 Share Posted October 4, 2008 Yes I agree, that's the issue with a server side sleep. Quote Link to comment https://forums.phpfreaks.com/topic/126895-solved-redirect/#findComment-657281 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.