Page 1 of 1

PHP Contact Form - Redirection

Posted: Wed Feb 11, 2009 10:32 pm
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?

Re: PHP Contact Form - Redirection

Posted: Wed Feb 11, 2009 10:45 pm
by Ziq
Hi

Read about the header function.

Re: PHP Contact Form - Redirection

Posted: Thu Feb 12, 2009 7:31 am
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 :(

Re: PHP Contact Form - Redirection

Posted: Thu Feb 12, 2009 8:15 am
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?

Re: PHP Contact Form - Redirection

Posted: Thu Feb 12, 2009 8:55 am
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");
}
 
?>

Re: PHP Contact Form - Redirection

Posted: Thu Feb 12, 2009 9:09 am
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?

Re: PHP Contact Form - Redirection

Posted: Thu Feb 12, 2009 9:57 am
by SuperShutts
A added that code to the top of my script and still was left with a blank page after testing

Re: PHP Contact Form - Redirection

Posted: Thu Feb 12, 2009 4:01 pm
by SuperShutts
Does anyone have any idea?

Re: PHP Contact Form - Redirection

Posted: Thu Feb 12, 2009 4:19 pm
by SuperShutts
Sorted...

Code: Select all

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