Hi I am having trouble getting redirecting to a thank you page after a simple html form has been completed. Can anyone help me fix this? Thanks! Tim <?php // set up mail details $mail_to = "timm@think-in.co.uk"; $mail_from = stripslashes($HTTP_POST_VARS['Email']); $mail_subject = "PRINT - IN - WEBSITE FORM"; $mail_headers = "FROM: $mail_from\r\n"; // grab details from http post array and iterate through each to build string $mail_body = ""; $mail_body .= "PRINT-IN - WEBSITE FORM\n"; while(list($key, $value) = each($HTTP_POST_VARS)) { $mail_body .= "\n$key = $value\n"; } //create mail footer message $mail_footer = "\n\nMailer enquiry for THINK-IN"; //concatinate mail_body and mail_footer $mail_body = $mail_body . $mail_footer; // send mail if (mail($mail_to, $mail_subject, $mail_body, $mail_headers)) { //echo ("<p>Enquiry Email Sent<p>"); $success = 1; } else { //echo ("<p>Error On Sending Mail</p>"); $success = 0; } ?> <TABLE width="300" border="0" cellspacing="0" cellpadding="0" > <TR> <TD colspan="2" class=std> <?php //create messsage besed on whether mail was sent or not if ($success == 1) echo "<script>window.location.href(\"http://www.example.com\");</script>"; else echo ("There has been an error sending your details please click back and try again</a>"); ?>
Replace: //echo ("<p>Enquiry Email Sent<p>"); PHP: with header('Location: http://www.example.com/thank-you.html'); exit(); PHP:
Hi, thanks for looking at this, the form sends but I recieve this message... Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/print-in.com/httpdocs/Library/send_details.php:4) in /var/www/vhosts/print-in.com/httpdocs/Library/send_details.php on line 78
That's because headers (like redirect headers) have to come before any other text. Put this as your first line of PHP code: ob_start(); PHP:
ok here is the code with those two amends, still get the warning message though...thanks for your help here. <HTML> <HEAD> <TITLE>WEBSITE FORM</TITLE> <script type="text/JavaScript"> <!-- function MM_goToURL() { //v3.0 var i, args=MM_goToURL.arguments; document.MM_returnValue = false; for (i=0; i<(args.length-1); i+=2) eval(args+".location='"+args[i+1]+"'"); } //--> </script> <STYLE type="text/css"> <!-- BODY { } A { COLOR: #666666; TEXT-DECORATION: none; } A:hover { TEXT-DECORATION: underline; } .small { FONT-SIZE: 8pt; FONT-FAMILY: Arial, Helvetica, sans-serif; } .std { FONT-SIZE: 8pt; FONT-FAMILY: Arial, Helvetica, sans-serif; } .heading { FONT-SIZE: 8pt; FONT-FAMILY: Tahoma; FONT-WEIGHT: BOLD; COLOR:#666666; } .bigheading { FONT-SIZE: 8pt; FONT-FAMILY: Tahoma; FONT-WEIGHT: BOLD; COLOR:#666666; } --> </STYLE> </HEAD> <BODY onLoad="MM_goToURL('http://www.print-in.com/index.php');return document.MM_returnValue"> <?php ob_start(); // set up mail details $mail_to = "timm@think-in.co.uk"; $mail_from = stripslashes($HTTP_POST_VARS['Email']); $mail_subject = "PRINT - IN - WEBSITE FORM"; $mail_headers = "FROM: $mail_from\r\n"; // grab details from http post array and iterate through each to build string $mail_body = ""; $mail_body .= "PRINT-IN - WEBSITE FORM\n"; while(list($key, $value) = each($HTTP_POST_VARS)) { $mail_body .= "\n$key = $value\n"; } //create mail footer message $mail_footer = "\n\nMailer enquiry for THINK-IN"; //concatinate mail_body and mail_footer $mail_body = $mail_body . $mail_footer; // send mail if (mail($mail_to, $mail_subject, $mail_body, $mail_headers)) { header('Location: http://www.print-in.com/thank-you.html'); exit(); $success = 1; } else { //echo ("<p>Error On Sending Mail</p>"); $success = 0; } ?> <TABLE width="300" border="0" cellspacing="0" cellpadding="0" > <TR> <TD colspan="2" class=std> <?php //create messsage besed on whether mail was sent or not if ($success == 1) echo ("<script>window.location.href(\"http://www.example.com\");</script>"); else echo ("There has been an error sending your details please click back and try again</a>"); ?> <BR> </TD> </TR> </TABLE> </BODY> </HTML>
Either have: <?php ob_start(); ?> then HTML code then the PHP code or... all the PHP code then the HTML code