badproduce Posted September 25, 2007 Share Posted September 25, 2007 I am working on a basic e-mail form.It is supposed to redirect the user to another page after email is sent. Here's my code: <?php if(isset($_POST['submit'])) { $to = "[email protected]"; $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 ""; mail($to, $subject, $body); // Change to the URL you want to redirect to $URL="http://www.jondoe.org/thankyou.html"; header ("Location: $URL"); } else { echo "blarg!"; } ?> If you can help me figure this out I would be happy. ps-real email and website name changed to protect the innocent. Link to comment https://forums.phpfreaks.com/topic/70579-solved-email-form-redirect/ Share on other sites More sharing options...
d.shankar Posted September 25, 2007 Share Posted September 25, 2007 What error are you getting ? Did you receive the email ? Link to comment https://forums.phpfreaks.com/topic/70579-solved-email-form-redirect/#findComment-354642 Share on other sites More sharing options...
hvle Posted September 25, 2007 Share Posted September 25, 2007 what is wrong with your script? Link to comment https://forums.phpfreaks.com/topic/70579-solved-email-form-redirect/#findComment-354644 Share on other sites More sharing options...
badproduce Posted September 25, 2007 Author Share Posted September 25, 2007 i get the warning Warning: Cannot modify header information - headers already sent by (output started at /home/content/m/y/g/mygiftncf/html/mailerwebmaster.php:2) in /home/content/m/y/g/mygiftncf/html/mailerwebmaster.php on line 23 I recieved the email but it doesn't redirect to my page Link to comment https://forums.phpfreaks.com/topic/70579-solved-email-form-redirect/#findComment-354648 Share on other sites More sharing options...
d.shankar Posted September 25, 2007 Share Posted September 25, 2007 Check this out. <?php $to = "[email protected]"; $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 ""; mail($to, $subject, $body); // Change to the URL you want to redirect to $URL="http://www.jondoe.org/thankyou.html"; header ("Location: $URL"); ?> Link to comment https://forums.phpfreaks.com/topic/70579-solved-email-form-redirect/#findComment-354649 Share on other sites More sharing options...
badproduce Posted September 25, 2007 Author Share Posted September 25, 2007 Thank you,it works great.You are a genius!! Link to comment https://forums.phpfreaks.com/topic/70579-solved-email-form-redirect/#findComment-354654 Share on other sites More sharing options...
d.shankar Posted September 25, 2007 Share Posted September 25, 2007 Thats because you were using an echo statement in between. I am glad that it worked. Link to comment https://forums.phpfreaks.com/topic/70579-solved-email-form-redirect/#findComment-354658 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.