williwaw Posted February 4, 2010 Share Posted February 4, 2010 First off, hi to everyone and thank you for checking this out. I am trying to have this open a url (in the same directory) instead of to this: $thankyou_message = "<p>Thankyou. Your message has been sent and I will contact you as soon as possible.</p>"; I would rather have this point somewhere back to my site as you can see it currently navigates people away without a way for them to get back. Thanks! <?php // Change to your own email address $your_email = "[email protected]"; // This is what is displayed in the email subject line // Change it if you want $subject = ""; // This is displayed if all the fields are not filled in $empty_fields_message = "<p style='color:#a00'>Please fill in all fields.</strong></p>\n"; // This is displayed when the email has been sent $thankyou_message = "<p>Thankyou. Your message has been sent and I will contact you as soon as possible.</p>"; // You do not need to edit below this line $name = stripslashes($_POST['txtName']); $email = stripslashes($_POST['txtEmail']); $message = stripslashes($_POST['txtMessage']); if (!isset($_POST['txtName'])) { } elseif (empty($name) || empty($email) || empty($message)) { echo $empty_fields_message; } else { /* // Stop the form being used from an external URL // Get the referring URL $referer = $_SERVER['HTTP_REFERER']; // Get the URL of this page $this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]; // If the referring URL and the URL of this page don't match then // display a message and don't send the email. if ($referer != $this_url) { echo "You do not have permission to use this script from another URL."; exit; } */ // The URLs matched so send the email mail($your_email, $subject, $message, "From: $name <$email>"); // Display the thankyou message echo $thankyou_message; echo $empty_fields_message; } ?> Thanks again! Cheers, Williwaw Quote Link to comment https://forums.phpfreaks.com/topic/190873-email-form-help/ Share on other sites More sharing options...
Hussam Posted February 4, 2010 Share Posted February 4, 2010 you can puta link under the thank you message and let them click on that link or you can redirect them to that page only in the email was sent successfully by doing this: if (mail($your_email, $subject, $message, "From: $name <$email>")) { header('Location: yourpage.html'); } else { // print the errors here } Quote Link to comment https://forums.phpfreaks.com/topic/190873-email-form-help/#findComment-1006561 Share on other sites More sharing options...
williwaw Posted February 4, 2010 Author Share Posted February 4, 2010 Thanks for your help Hussam! I think using the code you provided is the direction I am trying to go, but I am unsure where to place it. Sorry, I am a novice/noobie when it comes to php. Thanks again. you can puta link under the thank you message and let them click on that link or you can redirect them to that page only in the email was sent successfully by doing this: if (mail($your_email, $subject, $message, "From: $name <$email>")) { header('Location: yourpage.html'); } else { // print the errors here } Quote Link to comment https://forums.phpfreaks.com/topic/190873-email-form-help/#findComment-1006565 Share on other sites More sharing options...
Hussam Posted February 4, 2010 Share Posted February 4, 2010 instead of this in your code: // The URLs matched so send the email mail($your_email, $subject, $message, "From: $name <$email>"); // Display the thankyou message echo $thankyou_message; echo $empty_fields_message; put this: if (mail($your_email, $subject, $message, "From: $name <$email>")) {header('Location: yourpage.html');} else { echo $empty_fields_message; } the code can be alot cleaner but this should work for now! Quote Link to comment https://forums.phpfreaks.com/topic/190873-email-form-help/#findComment-1006572 Share on other sites More sharing options...
williwaw Posted February 4, 2010 Author Share Posted February 4, 2010 Weeeee... I got it to work, or shall I say you did Hussam. Thanks for your help! Cheers, Bill Quote Link to comment https://forums.phpfreaks.com/topic/190873-email-form-help/#findComment-1006612 Share on other sites More sharing options...
oni-kun Posted February 4, 2010 Share Posted February 4, 2010 Weeeee... I got it to work, or shall I say you did Hussam. Thanks for your help! Cheers, Bill Doesn't anyone put exit(); after their headers anymore? Quote Link to comment https://forums.phpfreaks.com/topic/190873-email-form-help/#findComment-1006613 Share on other sites More sharing options...
williwaw Posted February 4, 2010 Author Share Posted February 4, 2010 I'll give it a try...Thanks oni-kun Quote Link to comment https://forums.phpfreaks.com/topic/190873-email-form-help/#findComment-1006614 Share on other sites More sharing options...
Hussam Posted February 4, 2010 Share Posted February 4, 2010 Your welcome williwaw. Doesn't anyone put exit(); after their headers anymore? you don't really need to, some people do to prevent any code below from execution, however, this doesn't make sense because the code below is not going to get executed since the browser was redirected to a different page already. Quote Link to comment https://forums.phpfreaks.com/topic/190873-email-form-help/#findComment-1006629 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.