Go Back   kirupaForum > Development > Server-Side (PHP, SQL, ASP.NET, etc.)

Reply
 
Thread Tools Display Modes
Old 02-08-2010, 09:27 AM   #1
simplistik
PseudoMex
 
simplistik's Avatar
Location Tallahassee, FL

Posts 10,112
How To: Redirect the Kirupa "PHP Contact Form"

One of the most common questions that people as is how to redirect the "PHP Contact Form". And since people either fail at searching or are just to lazy here's how you do it. Here's the final code from the tutorial:
PHP Code:
<?php
if(isset($_POST['submit'])) {

    
$to "you@you.com";
    
$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 
"Data has been submitted to $to!";
    
mail($to$subject$body);

} else {

    echo 
"blarg!";

}
?>
change

PHP Code:
echo "Data has been submitted to $to!"
to

PHP Code:
header("Location: http://www.yourpage.com"); 

__________________
Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.
simplistik is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?

Old 03-31-2010, 12:24 PM   #2
Yeldarb
Registered User
Location Iowa

Posts 4,862
Simp - I don't know if it will make a difference but you may want the header change to come after the call to the mail() function just in case the browser redirects before the email gets sent.

__________________

Brad Dwyer Site|Brad Dwyer CV|Brad Dwyer Profile|Wakeboarding|Water Skiing
Yeldarb is offline   Reply With Quote
Old 03-31-2010, 12:29 PM   #3
simplistik
PseudoMex
 
simplistik's Avatar
Location Tallahassee, FL

Posts 10,112
Quote:
Originally Posted by Yeldarb View Post
Simp - I don't know if it will make a difference but you may want the header change to come after the call to the mail() function just in case the browser redirects before the email gets sent.
Yea good suggestion. Didn't really think to much about it I just know this question is asked at least once a week. So for those reading this his suggestion is to turn:

PHP Code:
    header("Location: http://www.yourpage.com");  
    
mail($to$subject$body); 
to

PHP Code:
    mail($to$subject$body); 
    
header("Location: http://www.yourpage.com"); 

__________________
Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.
simplistik is offline   Reply With Quote
Old 07-15-2010, 06:11 AM   #4
irkevin
Registered User
Or maybe

PHP Code:
 <?php 
if(isset($_POST['submit'])) { 

    
$to "you@you.com"
    
$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"
  
    if(
mail($to$subject$body)){
         
// If the mail was sent, then redirect
         
header("Location:  http://www.yourpage.com");  
    }else{
       
// Else display a message
       
echo 'An error occured while sending your message. Try again  later';
    } 

} else { 

    
//Display Form here


?>
irkevin is offline   Reply With Quote
Old 08-30-2010, 10:50 AM   #5
Wurd
Registered User
The second one is worth
Wurd is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:31 PM.

SHARE:

SUPPORTERS:

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com