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 = "[email protected]"; $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 Link to comment https://forums.phpfreaks.com/topic/92318-form-trouble/ 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!";} Link to comment https://forums.phpfreaks.com/topic/92318-form-trouble/#findComment-473003 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 Link to comment https://forums.phpfreaks.com/topic/92318-form-trouble/#findComment-473007 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 = "[email protected]"; $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 Link to comment https://forums.phpfreaks.com/topic/92318-form-trouble/#findComment-473027 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! Link to comment https://forums.phpfreaks.com/topic/92318-form-trouble/#findComment-473158 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 Link to comment https://forums.phpfreaks.com/topic/92318-form-trouble/#findComment-473161 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"); Link to comment https://forums.phpfreaks.com/topic/92318-form-trouble/#findComment-473164 Share on other sites More sharing options...
Sean_J Posted February 22, 2008 Author Share Posted February 22, 2008 Thanks alot, works great Link to comment https://forums.phpfreaks.com/topic/92318-form-trouble/#findComment-473559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.