Form Redirect

Hey I’ve got a form. It used to pass some HTML code depending on whether it passed or failed. I don’t want it to do that any more, I want to redirect to a success or failure page.

I tried using location: header but now it’s saying that the header has already been passed.

Which I assume is because when it sends the email it sends a header of the email?
or potentially because I am using two Location: header things

  1. Am I right?
  2. This seems like a fairly common thing to do, am I going about it the right way?
    (a) or which is the right way?
    (b) how do I resolve my issue?

Many thanks for your help, I can’t believe I couldn’t find this by searching… is this not “noob contact form redirect problem 1.a?”

		$to = "";
		$subject = "Homepage Enquiry";
		$email = $_POST['email'] ;
		$message = "Name: ".$_POST['name']."\
Tel: ".$_POST['tel']."\
Email: ".$_POST['email']."\
Subject: ".$_POST['enquirytb'];
		$headers = "From: ".$_POST['email'];
		$sent = mail($to, $subject, $message, $headers);
			if($sent) {header("Location:");}
				else {header("Location:");}

Your code is fine and will work, its where you put it that is the problem!
Headers are pedantic little buggers who demand to be the first thing sent to the browser. This means that nothing, and I mean NOTHING can be sent before them.
So no white space, echo statements or html can be before the header.

you can have as much php as you like as long as nothing goes out before it.

Put that block of code on line 1, position 1 and it should work.

Well that’s fine, but I have a slight problem in that there’s other pedantic little so and so’s which demand to be first in line.

&lt;meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"  /&gt;

for example. I believe it “simply has to be first in line”.

Then in terms of SEO I believe the Title and stuff needs to be high up??

At least my code is right that makes a change :slight_smile:

A team leader from Manchester huh? Good job :slight_smile:
I like your quote too :slight_smile:

Any suggestions regarding my above suggested issues? Or am I simply to do as told and it will work? Is there usually a better solution or is mine actually the correct one?

Many thanks for your help.

The php is all processed, done and dusted BEFORE it gets to the browser. Put it above the <meta> tags.


Born and bred, and proud of it

lol thanks

You are welcome.