schwinghammer Posted July 22, 2008 Share Posted July 22, 2008 Hey people, I'm new to the forum and new to PHP. I'm putting together a PHP email submit form. It's kind of a patchwork quilt of code, but it works...kind of. I have the fields and the submit button and a mailer.php file that directs the email. here's the code of that file: <?php if(isset($_POST['submit'])) { $to = "[email protected]"; $subject = "NEW MESSAGE FROM WEBSITE"; $fname_field = $_POST['fname']; $lname_field = $_POST['lname']; $email_field = $_POST['email']; $website_field = $_POST['website']; $coffee_field = $_POST['coffee']; $message = $_POST['message']; $body = "FirstName: $fname_field\n LastName: $lname_field\n E-Mail: $email_field\n Website: $website_field\n Coffee: $coffee_field\n Message:\n $message"; mail($to, $subject, $body); header("Location: http://www.blindacre.com/");die; } else { header("Location: http://www.blindacre.com/");die; } ?> If I use the 'echo' command instead of the 'header' everything works fine, except it's just an ugly white page that says whatever i tell it to. What I would like to do is re-direct the user to a nicely designed page and the 'header();' example is what I found, however I can't get it to work right. It's entirely possible that my syntax is way off. Thanks in advance for the help! Link to comment https://forums.phpfreaks.com/topic/116046-php-email-form-re-direct/ Share on other sites More sharing options...
john-formby Posted July 22, 2008 Share Posted July 22, 2008 <?php if(isset($_POST['submit'])) { $to = "[email protected]"; $subject = "NEW MESSAGE FROM WEBSITE"; $fname_field = $_POST['fname']; $lname_field = $_POST['lname']; $email_field = $_POST['email']; $website_field = $_POST['website']; $coffee_field = $_POST['coffee']; $message = $_POST['message']; $body = "FirstName: $fname_field\n LastName: $lname_field\n E-Mail: $email_field\n Website: $website_field\n Coffee: $coffee_field\n Message:\n $message"; mail($to, $subject, $body); header("Location: http://www.blindacre.com/");die; } The else section is outside of the if(isset($_POST['submit'])) { code so is automatically redirecting you to the site before you see the form. Link to comment https://forums.phpfreaks.com/topic/116046-php-email-form-re-direct/#findComment-596757 Share on other sites More sharing options...
schwinghammer Posted July 22, 2008 Author Share Posted July 22, 2008 Thanks, works swimmingly! Link to comment https://forums.phpfreaks.com/topic/116046-php-email-form-re-direct/#findComment-596788 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.