Comment form not submitting on valid CAPTCHA response!

Hi all,

My first post here :slight_smile: I’m using a comment form mailer script from ‘corrosiveonline.co.uk’ and in its basic form it works as it should. However, after I customized it to deal with input from my existing contact form it fails on valid CAPTCHA response (it successfully redirects to my error.php page if the CAPTCHA is entered incorrectly). I’ve done hours of research and tried to troubleshoot it but it just won’t work! An experienced PHP coder will probably spot the problem, so I thought I’d give this forum a go. I’ve ******'d out various bits for privacy. See code below:

Note: upon successful CAPTCHA response, the mailer does not redirect the user to thankyou.htm but instead displays an entirely blank page - mailer.php - as if it has paused in its execution… if I could only see some sort of error message! ???

[php]

<?php require_once('recaptchalib.php'); $privatekey = "********************************"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if(!$resp->is_valid) { header("Location: http://www.******.com/error.php"); die(); } $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $organization = $_POST['organization']; $consult = ($_POST['interested_in_consulting'])?"Yes":"No"; $train = ($_POST['interested_in_training'])?"Yes":"No"; $analyze = ($_POST['interested_in_analytical_serv'])?"Yes":"No"; $comments = $_POST['comments']; $formsub = $_POST['Submit']; if($formsub){ $mailMessage = "Hello, you have a new form submission from the *** website\n\n"; $mailMessage .= "First Name:" .$firstname."\n\n"; $mailMessage .= "Last Name:" .$lastname."\n\n"; $mailMessage .= "E-Mail:" .$email."\n\n"; $mailMessage .= "Organization:" .$organization."\n\n"; $mailMessage .= "Interested in Consulting Services:" .$consult."\n\n"; $mailMessage .= "Interested in Training Services:" .$train."\n\n"; $mailMessage .= "Interested in Analytical Services:" .$analyze."\n\n"; $mailMessage .= "Enquiry details:" .$comments."\n\n"; $header = "From: ******@******.com\r\n"; $header .= "Reply-To: ******@******.com\r\n"; $header .= "Return-Path: ******@******.com\r\n"; mail('******@******.com', 'Website Enquiry', $mailMessage, $header); header("Location: http://www.******.com/thankyou.htm"); exit; } ?>

[/php]

<div id="docform">
    
      <form action="mailer.php" method="post" id="frmRequest">
      
      <fieldset>
      
      <legend>Your Contact Details</legend>
      
      <p><span id="sprytextfield1">
      
        <label for="firstname">First Name:</label>
        
        <input  type="text" name="firstname" id="firstname" tabindex="10" />
        
        <span class="textfieldRequiredMsg">An entry is required.</span></span></p>
        
      <p><span id="sprytextfield4">
      
        <label for="lastname">Last Name:</label>
        
        <input type="text" name="lastname" id="lastname" tabindex="20" />
        
        <span class="textfieldRequiredMsg">An entry is required.</span></span></p>
        
      <p><span id="sprytextfield2">
      
        <label for="email">E-mail Address:</label>
        
        <input name="email" type="text" class="text" id="email" tabindex="30" />
        
        <span class="textfieldRequiredMsg">An entry is required.</span><span class="textfieldInvalidFormatMsg">Invalid e-mail format.</span></span></p>
        
      <p><label for="organization">Organization:</label>
      
        <input name="organization" type="text" class="text" id="organization" tabindex="40" /></p>
        
      </fieldset>
      
      <fieldset>
      
      <legend>Information Request</legend>
      
        <p>What would you like to know more about?</p>
        
        <p><input type="checkbox" name="interested_in_consulting" id="interested_in_consulting" tabindex="50" />
        
          <label for="consulting">Intelligence Solutions Consulting</label><br />
          
          <input type="checkbox" name="interested_in_training" id="interested_in_training" tabindex="60" />
          
          <label for="training">Intelligence Training Solutions</label><br />
          
          <input type="checkbox" name="interested_in_analytical_serv" id="interested_in_analytical_serv" tabindex="70" />
          
          <label for="analysis">Analytical Services</label></p>
        
        <p><label for="comments">Please enter the details of your enquiry here:</label><br />
        
          <textarea name="comments" cols="50" rows="8" class="text" id="comments" tabindex="80"></textarea></p>
          
      </fieldset>
      
      <fieldset>
      
      <legend>Anti-Spam</legend>
      
      	<p>
		
		<?php require_once('recaptchalib.php');

		$publickey = "**************************************";
		
		echo recaptcha_get_html($publickey);?>
        
        </p>
      
		<p><input type="submit" name="submit" id="submit" value="Submit" tabindex="90" /></p>
          
      </fieldset>
      
      </form>
      
    </div>

Make sure you have no any output in your mailer.php
If you have any single space or any other char above the header() function call - this will cause error.

Thanks for the response. Yep, spaces before the header function was one of the first things that I checked. I can’t see any. I’m confused because the original script works but this one pauses in its execution for an unknown reason. Maybe I should post them side by side and someone might spot a functional difference:

Original Script:
[php]<?php
require_once(‘recaptchalib.php’);
$privatekey = “XXXXXXXXXXXXXXXXXXXXXX”;
$resp = recaptcha_check_answer ($privatekey,
$_SERVER[“REMOTE_ADDR”],
$_POST[“recaptcha_challenge_field”],
$_POST[“recaptcha_response_field”]);
if(!$resp->is_valid) {
header(“location:error.php”);
die();
}
//these are the form results
$name = $_POST[‘name’];
$email = $_POST[‘email’];
$enquiry = $_POST[‘enquiry’];
$formsub = $_POST[‘Submit’];
if($formsub){

//this creates the body of the mail message
$mailMessage = “The message is: Hi XXXX. You have a message from the website\n\n”;
$mailMessage .= “Name:” .$name."\n\n";
$mailMessage .= “E-Mail:” .$email."\n\n";
$mailMessage .= “Enquiry:” .$enquiry."\n\n";
$header = "From:[email protected]\r\n";
$header .= “Reply-To: [email protected]\r\n”;
$header .= “Return-Path: [email protected]\r\n”;
mail(‘[email protected]’, ‘Website Enquiry’, $mailMessage,$header);

header(“location:thanks.php”);
exit;

}
?>[/php]

Modified Script:
[php]<?php
require_once(‘recaptchalib.php’);
$privatekey = "";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER[“REMOTE_ADDR”],
$_POST[“recaptcha_challenge_field”],
$_POST[“recaptcha_response_field”]);
if(!$resp->is_valid) {
header("Location: http://www.
.com/error.php");
die();
}
$firstname = $_POST[‘firstname’];
$lastname = $_POST[‘lastname’];
$email = $_POST[‘email’];
$organization = $_POST[‘organization’];
$consult = ($_POST[‘interested_in_consulting’])?“Yes”:“No”;
$train = ($_POST[‘interested_in_training’])?“Yes”:“No”;
$analyze = ($_POST[‘interested_in_analytical_serv’])?“Yes”:“No”;
$comments = $_POST[‘comments’];
$formsub = $_POST[‘Submit’];
if($formsub){
$mailMessage = “Hello, you have a new form submission from the *** website\n\n”;
$mailMessage .= “First Name:” .$firstname."\n\n";
$mailMessage .= “Last Name:” .$lastname."\n\n";
$mailMessage .= “E-Mail:” .$email."\n\n";
$mailMessage .= “Organization:” .$organization."\n\n";
$mailMessage .= “Interested in Consulting Services:” .$consult."\n\n";
$mailMessage .= “Interested in Training Services:” .$train."\n\n";
$mailMessage .= “Interested in Analytical Services:” .$analyze."\n\n";
$mailMessage .= “Enquiry details:” .$comments."\n\n";
$header = "From: ******@
.com\r\n";
$header .= "Reply-To: ******@
.com\r\n";
$header .= "Return-Path: ******@
.com\r\n";
mail('
@
****.com’, ‘Website Enquiry’, $mailMessage, $header);
header(“Location: http://www.******.com/thankyou.htm”);
exit;
}
?>[/php]

ok, looks like i wasn’t properly treating checkboxes as I should be - as an array… there are more bugs in my code so please consider this post solved.

Sponsor our Newsletter | Privacy Policy | Terms of Service