Jump to content

Redirecting!


jwk811

Recommended Posts

I have a form that leads to a script to be emailed. When the person submits the form and goes to the script page I want to have them redirected to another page and I know it's possible but I just can't figure it out. So basically how do I make a page go to another page once someone views it?
Link to comment
Share on other sites

[quote author=jwk811 link=topic=110120.msg444547#msg444547 date=1159676415]
do you mean if i have the redirect code in the script then i can't send the email? and where would i put the line?
[/quote]
no you can do a mail function. you just can't have any html output before a header. example:

mail(...);
header(...);

is fine.

mail(...);
echo "blah";
header(..);

is not.
Link to comment
Share on other sites

Okay thanks. In this code.
[code]if(mail(...)) header("Location: http:///www.domain.com");
else {
//something
}[/code]
I would put
[code]if (mail($to;$message;$subject;$header)) header ('Location: http://www.redirectpage.com')
else {
echo "there was a problem"
}[/code]
is that how i should do it?
Link to comment
Share on other sites

okay, im getting a few problems...
this is my code that should send an email and redirect to another page
[code]<?php
ob_start();
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$to = "(my-email)";
$subject = "Selling Chips";
$message = "<b>$name</b>'s comment.---$comment.";
$headers = "From: $email";
mail($to,$subject,$message,$headers);
if (mail($to,$subject,$message,$headers)) header("Location: thankyou.php");
else "echo A problem occured";
ob_end_flush();
?>[/code]
is that right? because i get this page coming up.. its the page that the form was directed to with a warning at the top...
[code]Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/w/k/jwk811/html/process.php:5) in /home/content/j/w/k/jwk811/html/process.php on line 37
[/code]
And actually get sent two emails so the if (mail...) is actually sending me another.. whats the problem? cant figure it out
Link to comment
Share on other sites

okay that script in and of itself does not need the ob_start/ob_end_flush functions.  Is this script a code block in a larger script, or is it being included in another script? If so, again, there cannot be any html output before the header.  you will have to extend your ob stuff to include the other stuff.

If this script is in its own file and it's not being included into something else, then check to make sure you don't even have a blank line before your <?php tag, cuz that counts as html output
Link to comment
Share on other sites

Thank you very much. But just one more thing.. the if(mail..) is sending me another email.. i got the redirect to work now but what about the email and if something did go wrong would the else stament say the error if the if thing isnt going right?
Link to comment
Share on other sites

you are getting 2 emails because you are sending 2 emails.

[code]
mail($to,$subject,$message,$headers); // take out this line
if (mail($to,$subject,$message,$headers)) header("Location: thankyou.php");
else echo "A problem occured";
[/code]

you need to take one of them out. i suppose you should take out the first one, so as to leave in some error handling. Also on your else statement, move the " you have your quotes wrapped around echo.  (I changed it in the code I listed, for reference).
Link to comment
Share on other sites

you need to setup some error checking for your form. wrap that thing inside some more conditioning.

VERY basic example:
[code]
if (!$_POST['name'] or !$_POST['email']) {
  echo "please fill out your form";
else {
  if (mail($to,$subject,$message,$headers)) header("Location: thankyou.php");
  else echo "A problem occured";
}
[/code]
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.