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.

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.