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
SuperShutts
Forum Newbie
Posts: 6 Joined: Wed Feb 11, 2009 10:29 pm
Post
by SuperShutts » Wed Feb 11, 2009 10:32 pm
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?
Ziq
Forum Contributor
Posts: 194 Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh
Post
by Ziq » Wed Feb 11, 2009 10:45 pm
Hi
Read about the
header function.
SuperShutts
Forum Newbie
Posts: 6 Joined: Wed Feb 11, 2009 10:29 pm
Post
by SuperShutts » Thu Feb 12, 2009 7:31 am
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
Post
by mattpointblank » Thu Feb 12, 2009 8:15 am
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
Post
by SuperShutts » Thu Feb 12, 2009 8:55 am
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");
}
?>
Ziq
Forum Contributor
Posts: 194 Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh
Post
by Ziq » Thu Feb 12, 2009 9:09 am
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
Post
by SuperShutts » Thu Feb 12, 2009 9:57 am
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
Post
by SuperShutts » Thu Feb 12, 2009 4:01 pm
Does anyone have any idea?
SuperShutts
Forum Newbie
Posts: 6 Joined: Wed Feb 11, 2009 10:29 pm
Post
by SuperShutts » Thu Feb 12, 2009 4:19 pm
Sorted...
Code: Select all
if ($success) {
echo "<script>navigate('contactthanks.html')</script>";
exit();
}
Thanks for trying tho guys