php logic

Hi,
I have a php email code that does the job well except for the echo/print messages. I know the logic is wrong but I’m not yet good enough with php to find it, and I’ve tried several different arrangements.
The problem is that it gives the same message no matter what entries are made: “The reCAPTCHA failed with this message:
Please try again.
You have not entered a name, please go back and try again”
I need help from one of you php guys/gals out there, please.
Greatly appreciated,
Lee

<? ob_start(); ?> #recaptcha_error_box { width:30%; border:medium groove #A00; background-color:#FF9; padding:1em; color:#900; font-weight:bold; font-size:80%;} <?php require_once('recaptchalib.php'); $privatekey = "6LcDacUSAAAAAJqFvJV5iOSsG8x6RnTLoIU6kg7s"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly echo '
The reCAPTCHA failed with this message: '.$response->error.'
Please try again.
';} else { $to = $_REQUEST['sendto'] ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = "Web Contact Data"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Email"} = "Email"; $fields{"businesstype"} = "Type of Business"; $fields{"Phone"} = "Phone"; $fields{"designcheck"} = "New Design?"; $fields{"pages"} = "Est. Number of Pages"; $fields{"forms"} = "Do you need Forms?"; $fields{"optimize"} = "Search Engine Optimization?"; $fields{"presentsite"} = "Your Present Website URL"; $fields{"admire"} = "Websites that you Admire"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $subject2 = "Thank you for contacting us"; $headers2 = "From: [email protected]";} $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, you may email me directly at [email protected]"; if($name == '') {print "You have not entered a name, please go back and try again";} else { if($from == '') {print "You have not entered an email, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) {header( "Location: http://www.leedoeswebsites.com/thanks.html"); }else {print "We encountered an error sending your mail, please notify [email protected]";} } } ?> <? ob_flush(); ?>

Hi,
I got it finally! Just needed to rearrange the IF statements. Here is the final for anyone who might have the same problem.
Lee

<? ob_start(); ?> <?php require_once('recaptchalib.php'); $privatekey = "abcdefganda123456"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); $to = $_REQUEST['sendto'] ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = "Web Contact Data"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Email"} = "Email"; $fields{"businesstype"} = "Type of Business"; $fields{"Phone"} = "Phone"; $fields{"designcheck"} = "New Design?"; $fields{"pages"} = "Est. Number of Pages"; $fields{"forms"} = "Do you need Forms?"; $fields{"optimize"} = "Search Engine Optimization?"; $fields{"presentsite"} = "Your Present Website URL"; $fields{"admire"} = "Websites that you Admire"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $subject2 = "Thank you for contacting us"; $headers2 = "From: [email protected]"; $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, you may email me directly at [email protected]"; if($Name == '') {echo 'You have not entered a name, please go back and try again';} else { if($from == '') {echo 'You have not entered an email, please go back and try again';} else { if (!$resp->is_valid) { echo 'The reCAPTCHA failed with this message. Please try again.'; } else{ $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) {header( "Location: http://www.leedoeswebsites.com/thanks.html"); }else {print "We encountered an error sending your mail, please notify [email protected]";} } } } ?> <? ob_flush(); ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service