Sean_J Posted February 21, 2008 Share Posted February 21, 2008 Hello Guys, I created a basic email form using an online form generater. Instead on seeing a message saying "Success! Your email was sent!" . Would it be possible to redirect them to another page on my website? If so could someone please show me how as I am a complete novice? The generator has come up with the following coding. <?php $EmailFrom = $_POST['EmailFrom']; $name_ = Trim($_POST['name_']); $age = Trim($_POST['age']); $location = Trim($_POST['location']); $EmailTo = "seanj@hotmail.com"; $Subject = ""; /// Add a subject $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (!$validationOK) { echo "Error! Email was not sent. Please check you code."; exit; } $Body = ""; $Body .= "Name :\n$name_\n\n"; $Body .= "Age:\n$age\n\n"; $Body .= "Location:\n$location\n\n"; if($Subject == NULL) {$Subject = "From $EmailFrom";} $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); if ($success){ echo "Success! Your email was sent!";} else{ echo "Error! Your email was not sent!";} ?> Thank you in advance Sean Quote Link to comment Share on other sites More sharing options...
fesan Posted February 21, 2008 Share Posted February 21, 2008 You can try this! Works for me..... if ($success){ header('location:*your address*'); } else{ echo "Error! Your email was not sent!";} Quote Link to comment Share on other sites More sharing options...
craygo Posted February 21, 2008 Share Posted February 21, 2008 if you want to show the message then redirect you can use a html META tag to wait a couple seconds to show the message then redirect. Ray Quote Link to comment Share on other sites More sharing options...
Sean_J Posted February 21, 2008 Author Share Posted February 21, 2008 Thank you for your replies. Fesan, Should the script look like this if I wanted to redirect them to my homepage <?php $EmailFrom = $_POST['EmailFrom']; $name_ = Trim($_POST['name_']); $age = Trim($_POST['age']); $location = Trim($_POST['location']); $EmailTo = "seanj@hotmail.com"; $Subject = ""; /// Add a subject $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (!$validationOK) { echo "Error! Email was not sent. Please check you code."; exit; } $Body = ""; $Body .= "Name :\n$name_\n\n"; $Body .= "Age:\n$age\n\n"; $Body .= "Location:\n$location\n\n"; if($Subject == NULL) {$Subject = "From $EmailFrom";} $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); if ($success){ header('location:*http://www.mysite.com/*'); } else{ echo "Error! Your email was not sent!";} ?> Thanks again Sean Quote Link to comment Share on other sites More sharing options...
fesan Posted February 21, 2008 Share Posted February 21, 2008 Yea... that looks right! I have not tried out your code... But you'll find out if it works or not! I use the header code to redirect after a form on my own page so it should work perfect! Quote Link to comment Share on other sites More sharing options...
Sean_J Posted February 21, 2008 Author Share Posted February 21, 2008 I'll try it out mate, thanks for yor help Sean Quote Link to comment Share on other sites More sharing options...
revraz Posted February 21, 2008 Share Posted February 21, 2008 You should use something like header ("location: index.php"); Quote Link to comment Share on other sites More sharing options...
Sean_J Posted February 22, 2008 Author Share Posted February 22, 2008 Thanks alot, works great Quote Link to comment 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.