PHP Contact Form - Redirection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SuperShutts
Forum Newbie
Posts: 6
Joined: Wed Feb 11, 2009 10:29 pm

PHP Contact Form - Redirection

Post by SuperShutts »

Hey Guys,

I have developed this code to send contact form data to my email address...

Code: Select all

<?php$name = $_POST['name'];
$email = Trim($_POST['email']);
$subject = Trim($_POST['subject']);
$message = Trim($_POST['message']);
$EmailTo = "info@squiggledesigns.co.uk";
$Subject = "Squiggle Designs Contact Form";
 
$validationOK=true;if (Trim($email)=="") 
$validationOK=false;if (!$validationOK) {  echo "Error! Message was not sent. Please check your details and try again.";  exit;}
 
$Body .= "Name: $name\n\n";
$Body .= "Subject: $subject\n\n";
$Body .= "Message: $message\n\n";
$Body .= "From: $email\n\n";if($subject == NULL) {$subject = "Squiggle Designs Contact Form: $EmailFrom";}
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success){ echo "Thanks";
}else{  echo "Error! Your email was not sent!";}?>
Where it says:

Code: Select all

if ($success){ echo "Thanks";
}else{  echo "Error! Your email was not sent!";}
Instead of it saying "thanks" or "Error! Your email was not sent" I would like it to redirect the user to "contactthanks.html"

Any Ideas?
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: PHP Contact Form - Redirection

Post by Ziq »

Hi

Read about the header function.
SuperShutts
Forum Newbie
Posts: 6
Joined: Wed Feb 11, 2009 10:29 pm

Re: PHP Contact Form - Redirection

Post by SuperShutts »

Code: Select all

if ($success){ 
    header("Location: http://www.squiggledesigns.co.uk/contactthanks.html");
}
else{  echo "Error! Your email was not sent!";}
This is the amended code, but upon success I still get a blank .php page (contactform.php) i'm stuck :(
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: PHP Contact Form - Redirection

Post by mattpointblank »

You can only use the header() function BEFORE sending any other output to the page - are you doing anything else in the code before you do the redirect?
SuperShutts
Forum Newbie
Posts: 6
Joined: Wed Feb 11, 2009 10:29 pm

Re: PHP Contact Form - Redirection

Post by SuperShutts »

I have removed parts of the code that are no longer important but still get a blank page...

Code: Select all

<?php
$name = $_POST['name'];
$email = Trim($_POST['email']);
$subject = Trim($_POST['subject']);
$message = Trim($_POST['message']);
 
$EmailTo = "info@squiggledesigns.co.uk";
$Subject = "Squiggle Designs Contact Form";
 
$Body .= "Name: $name\n\n";
$Body .= "Subject: $subject\n\n";
$Body .= "Message: $message\n\n";
$Body .= "Email: $email\n\n";
 
$success = mail($EmailTo, $Subject, $Body, "From: <$name>");
 
if ($success){ 
    header("Location: http://www.squiggledesigns.co.uk/contactthanks.html");
}
 
?>
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: PHP Contact Form - Redirection

Post by Ziq »

Try this

Code: Select all

<?php
ini_set('dispaly_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);
//  ...
What do you have in an output?
SuperShutts
Forum Newbie
Posts: 6
Joined: Wed Feb 11, 2009 10:29 pm

Re: PHP Contact Form - Redirection

Post by SuperShutts »

A added that code to the top of my script and still was left with a blank page after testing
SuperShutts
Forum Newbie
Posts: 6
Joined: Wed Feb 11, 2009 10:29 pm

Re: PHP Contact Form - Redirection

Post by SuperShutts »

Does anyone have any idea?
SuperShutts
Forum Newbie
Posts: 6
Joined: Wed Feb 11, 2009 10:29 pm

Re: PHP Contact Form - Redirection

Post by SuperShutts »

Sorted...

Code: Select all

if ($success) {
echo "<script>navigate('contactthanks.html')</script>";
exit();  
}
Thanks for trying tho guys
Post Reply