Jump to content

Mail Form Redirect to Thankyou Page - php newbe


Marcus2000

Recommended Posts

Hi people,

 

I am a complete newbe to php but can some one please help us out a little with a bit of code?

 

Basically i have a contact form, when the user submits the form it gets processed by my php page and the data sent of to my email address.

 

The thing is I have wrote most of the code for this and i think it should work, however i want to add a bit of code that re-directs the user to

a "thank you" page after they submit the form.

 

I hope that makes sense, please check out the code below and please let me know what and where to put the re-direct code, please

also let me know if the code i have written so far is correct.

 

my code

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

$to = "me@my_email_address.com";
$subject = "Contact Form";

$name = 		$_POST['name'];
$comp_name = 	$_POST['company_name'];
$email = 		$_POST['email'];
$phone = 		$_POST['contact_number'];
$location = 	$_POST['location'];
$message = 		$_POST['message'];

$body = 		"From: $name\n E-Mail: $email\n Company Name: $comp_name\n Contact Number: $phone:\n Location: $location:\n Message:\n $message";

mail($to, $subject, $body); }


?>

 

Cheers people, hope some one can help.

Try this out

 

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

$to = "me@my_email_address.com";
$subject = "Contact Form";

$name = 		$_POST['name'];
$comp_name = 	$_POST['company_name'];
$email = 		$_POST['email'];
$phone = 		$_POST['contact_number'];
$location = 	$_POST['location'];
$message = 		$_POST['message'];

$body = 		"From: $name\n E-Mail: $email\n Company Name: $comp_name\n Contact Number: $phone:\n Location: $location:\n Message:\n $message";

$sendit= @mail($to, $subject, $body); 

if($sendit){

header('Location: yourlocation');

}else{ echo "Email failed to send";}

}

?>

 

the header can be defined in numerous ways. If you want it to go to a new site, write

 

header('Location: http://www.thesite.com/');

 

if you want it to go to a page in the same directory as yours, do something like this

 

header('Location: thankyou.php');

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.