PDA

View Full Version : PHP Redirect


Winterworks
02-23-2009, 02:35 PM
I have a PHP contact code on my site... Right now, after you submit a contact form, it comes up with...

Data has been submitted to $to!

Because of the codes...

echo "Data has been submitted to $to!";
mail($to, $subject, $body);

In the .php file. Now, instead of it showing that, how can I make it redirect to another page instead?

CoolHandLuc
02-23-2009, 02:48 PM
<?php
header("Location: http://www.example.com/"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>

Winterworks
02-23-2009, 03:02 PM
that's not my whole code.

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

$to = "mikemersereau@hotmail.com";
$subject = "Client Testimonial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

$body = "From: $name_field\n Email: $email_field\n Testimonial:\n $message";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {

echo "error";

}
?>

I just need to know what to put where it says the "echo "Data has been...""

ragtek
02-23-2009, 03:05 PM
1.
$body = "From: $name_field\n Email: $email_field\n Testimonial:\n $message";

mail($to, $subject, $body);
header("Location: http://www.example.com/"); /* Redirect browser */
exit();
}

the redirect have to be after the mail function!

Winterworks
02-23-2009, 03:06 PM
ah, thank you very much!

TigerC10
02-23-2009, 03:51 PM
I recommend something a little more standard...


$vbulletin->url = 'index.php' . $vbulletin->session->vars['sessionurl_q'];
eval( print_standard_redirect("Data has been submitted to ".$to."!", false, true) );


That way, it keeps the look of your style, and doesn't deal with the complications that come with the above samples.

Winterworks
02-23-2009, 03:55 PM
sorry, you probably do not know this, but it is not for vbulletin, just for a general webpage.

TigerC10
02-23-2009, 04:02 PM
Oh, I see. Then don't use the exit() function (it does some wonky things between different versions of PHP).


ob_start();

//your code
echo "Data has been submitted to $to!";
mail($to, $subject, $body);

header("Location: http://www.google.com");
ob_end_flush();


This is much better.