PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Old January 25th, 2013, 01:17 PM
Sunnyoak Sunnyoak is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 Sunnyoak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 10 sec
Reputation Power: 0
PHP coding Help

Hi
I have a form working on a site but want to add a captcha. I have added the code but I get the following error on Submission
Quote:
Message has been sent
Warning: Cannot modify header information - headers already sent by (output started at booking2.php:92) in /booking2.php on line 93
Full Address Removed.

The form used to send the visitor to a "thank you" page but since adding the new script this doesn't happen. I am receiving the form but I can not get it to rediect to the thank you page.
Any help gratefully received.

I have included the php script without exact urls for security
PHP Code:
<?  include_once $_SERVER['DOCUMENT_ROOT'] . '/contact/securimage/securimage.php'$securimage = new Securimage();   if ($securimage->check(strtolower($_POST['passcode'])) == false) {  print "<h2>Incorrect verification code</h2>Please hit 'back' and try again -" $_POST['passcode']; exit;  } else {  foreach($_POST as $key => $val){          $val str_replace("'"""$val);         $val str_replace("\\"""$val);         $val str_replace("`"""$val);         $val str_replace("<"""$val);         $val str_replace(">"""$val);         $val str_replace("`"""$val);         $val str_replace("!"""$val);         $val str_replace("|"""$val);         $val str_replace("MIME"""$val);          $_POST[$key] = $val; }  require("class.phpmailer.php"); $mail = new PHPMailer();  //Your SMTP servers details  $mail->IsSMTP();               // set mailer to use SMTP $mail->Host = "mail.xxxxx.";  // specify main and backup server or localhost $mail->SMTPAuth = true;     // turn on SMTP authentication $mail->Username = "XXXXX";  // SMTP username $mail->Password = "XXXXXX"; // SMTP password //It should be same as that of the SMTP user  $redirect_url = "(XXXXXXX)"; //Redirect XXXafter submit the form  $mail->From = $mail->username;    //Default From email same as smtp user $mail->FromName = $_POST['email']; $mail->From = $mail->username;    //Default From email same as smtp user $mail->FromName = $_POST['email'];  $mail->AddAddress("andyhill@.com");  $mail->addCC("maggie@."); $mail->addBCC("maggie@.");   //Email address where you wish to receive/collect those emails.  $mail->WordWrap = 50;                                 // set word wrap to 50 characters $mail->IsHTML(true);                                  // set email format to HTML  $mail->Subject = $_POST['subject']; $message = "Email Address :".$_POST['email']." <br>  Name  :".$_POST['fullname']." <br> Address:".$_POST['address']."  <br>  Daytime Telephone :".$_POST['daytime']."  <br>  Evening Telephone :".$_POST['evening']."  <br>  Arrival Date :".$_POST['arrival']."  <br>  Departure Date :".$_POST['departure']."  <br> Number of Nights :".$_POST['nights']."  <br> Guest 1 :".$_POST['guest1']." \r\n  <br>  Guest 2 :".$_POST['guest2']." \r\n  <br>  Guest 3 :".$_POST['guest3']." \r\n  <br>  Guest 4 :".$_POST['guest4']." \r\n  <br>  Guest 5 :".$_POST['guest5']." \r\n <br>  Guest 6 :".$_POST['guest6']." \r\n  <br>  Guest 7 :".$_POST['guest7']." \r\n <br>  Guest 8 :".$_POST['guest8']." \r\n  <br>  Guest 9 :".$_POST['guest9']." \r\n  <br>  Guest 10 :".$_POST['guest10']." \r\n <br>  Weekly Rate :".$_POST['rate']." <br>  Pool Heating :".$_POST['pool']." \r\n <br>  Currency :".$_POST['currency']."   Amount :".$_POST['amount']." <br>  Party Leader :".$_POST['leader']." <br>  Dated :".$_POST['date']; $mail->Body    = $message;  if(!$mail->Send()) {    echo "Message could not be sent. <p>";    echo "Mailer Error: " . $mail->ErrorInfo;    exit; }  echo "Message has been sent"; header("Location: $redirect_url"); }  ?>


Line 93 is

header("Location: $redirect_url");
}

I'm sure it must be something so silly but I can't work it out.
Cheers
Maggie

Reply With Quote
Old January 25th, 2013, 04:24 PM
MatthewJ MatthewJ is offline
Contributing User
Click here for more information.
 
Join Date: May 2007
Location: Davenport, Iowa
Posts: 1,008 MatthewJ User rank is Private First Class (20 - 50 Reputation Level)MatthewJ User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 6 Days 9 h 36 m 46 sec
Reputation Power: 8
PHP Code:
echo "Message has been sent"


That line being added right before the redirect is the issue. A header redirect cannot be called after any content has been sent to the browser. Even white space etc.

So, when you try to echo the result, the headers send that content... then the redirect tries to fire and the headers have already been sent.

I would append a success flag to the redirect url like

PHP Code:
 header("Location: location_of_file_to_redirect_to.php?mailsent=t"); 


then you can check for the flag on the landing page with $_GET and display the success message there.

Even if it would work, your visitor would only see the success message for as long as it takes php to execute the header redirect. Which as you can imagine is not very long.

Hope that helps,

Matt

Reply With Quote
Old January 26th, 2013, 08:14 AM
Sunnyoak Sunnyoak is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 Sunnyoak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 10 sec
Reputation Power: 0
Hi Matthew
I changed that line but still had the same error. If I remove the header line completely I get the generic reponse "Message has been sent"

What I don't understand is that the script sent the visitor to the thank you html page prior to me adding the Captacha script at the top and now it will not redirect to the url.

Obviously I have something wrong somewhere.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > PHP coding Help


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap