is there a command to do this. so for example you can have a php that does a store to the database and then goes somewhere else.. Thanks
well i did and i am using the code <?php header("Location: http://www..../thanks.htm"); ?> <?php $name = $_POST["aname"]; $fromadd = $_POST["aemail"]; $phone = $_POST["atelephone"]; $jtitle= $_POST["ajtitle"]; $company= $_POST["acompany"]; $to = "...@yahoo.com"; $subject = "Brochure Request"; $body = "This is a request from the website for a .....,\n\nThe requst has come from ".$name."\n\nTheir phone number is ".$phone."\n\nThey are from the company ".$company."\n\nThier Job Title is ".$jtitle; $headers = "From: ".$fromadd."\r\n" . "X-Mailer: php"; if (mail($to, $subject, $body, $headers)) { echo("<p>Message sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> Code (markup): but it just shows message sent... i want it to send the email and goto thanks.htm what is wrong?
header("Location: http://www..../thanks.htm"); exit(); // you need to exit after a Location header is sent PHP:
hmm if i use that the page doesnt send the email or redirect.. is just blank <?php header("Location: http://www.....co.uk/contactthanks.html"); exit(); ?> <?php $name = $_POST["name"]; $fromadd = $_POST["email"]; $phone = $_POST["telephone"]; $jtitle= $_POST["jtitle"]; $company= $_POST["company"]; $to = "...@yahoo.com"; $subject = "Brochure Request"; $body = "This is a request from the website for a ...Brochure,\n\nThe requst has come from ".$name."\n\nTheir phone number is ".$phone."\n\nThey are from the company ".$company."\n\nThier Job Title is ".$jtitle; $headers = "From: ".$fromadd."\r\n" . "X-Mailer: php"; if (mail($to, $subject, $body, $headers)) { echo("<p>Message sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> Code (markup):
1. You cannot have any output to the page before header("Location: ") is called, it has to be the first thing thats sent to the browser. 2. exit() means just that, when you're driving and you take exit 123 on the highway, you won't make it to exit 124 ...same idea So.... send your email without outputting *anything* to the page, not even a white space, then use the header location to redirect to your next page.
You can always place the header command after sending the email, but you have to understand that you can't send data to the browser then send a location header: it's not 'legal' from an HTTP POV. If you want to give feedback to the user you either need to give it at the page where you are redirecting them to, or instead of using header send a meta refresh in the HTML you are sending.
Technically if you turn on output buffering (ob_start()) then you can have echos before you change the header() because it doesn't actually send out anything until it reaches the end of catches a flush() or other related function. Put your header() after you send the email, and drop an exit; after it.
If you wanted to, you could always use an HTML redirect in lieu of the PHP header way.... that won't give you an error when you try to output lines. The only problem is that your user might not like being redirected when he's/she's not expecting it.
Gross. If you're talking about in the header then it's still virtually the same problem, and if you're talking Javascript that's still less efficient since not everyone has javascript enabled (yes, a small percentage of people have it disabled)
If you want it to send the email, then go to thanks.htm, the header() call should go in place of the "message sent" echo statement. <?php $name = $_POST["aname"]; $fromadd = $_POST["aemail"]; $phone = $_POST["atelephone"]; $jtitle= $_POST["ajtitle"]; $company= $_POST["acompany"]; $to = "...@yahoo.com"; $subject = "Brochure Request"; $body = "This is a request from the website for a .....,\n\nThe requst has come from ".$name."\n\nTheir phone number is ".$phone."\n\nThey are from the company ".$company."\n\nThier Job Title is ".$jtitle; $headers = "From: ".$fromadd."\r\n" . "X-Mailer: php"; if (mail($to, $subject, $body, $headers)) { header("Location: http://www..../thanks.htm"); echo 'Delete this line after testing but tell me if this shows up and page is still not redirecting...'; exit(); } else { echo("<p>Message delivery failed...</p>"); } ?> PHP: