iVazanity Posted November 4, 2015 Share Posted November 4, 2015 Hello,I created a new form with reCaptcha and it works perfectly.My problem is, if a user fills out the form and forgets to use the captcha, the mail will be sent anyways..Whats the problem? Whats missing in my Code? Another problem is, if a user went to the processing page and refreshes this page the mail is sent a second time. That shouldn't be like that.. My HTML Code: <!DOCTYPE html> <html > <head> <meta charset="UTF-8"> <meta name="description" content="Kontaktieren Sie hier Mario Fracasso"> <meta name="keywords" content="contact,kontakt,mario,o,mario,schreiben,websites,offer"> <meta name="author" content="Mario"> <title>Contact - Mario</title> <link rel="stylesheet" href="css/style.css"> <script src='https://www.google.com/recaptcha/api.js'></script> </head> <body> <div id="form-main"> <div id="form-div"> <h1>Contact - Mario</h1> <hr> <form action="php/form_process.php" method="post" class="form" id="form1"> <p class="name"> <input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="First Name, Last Name" id="name" /> </p> <p class="email"> <input name="email" type="email" class="validate[required,custom[email]] feedback-input" id="email" placeholder="Email" /> </p> <p class="text"> <textarea name="text" class="validate[required,length[6,300]] feedback-input" id="comment" placeholder="Message"></textarea> </p> <div class="g-recaptcha" data-sitekey="-------"></div> <p> <div class="submit"> <input type="submit" value="SEND" id="button-blue"/> <div class="ease"></div> </div> </form> <footer> <p>© Mario</p> </footer> </div> </div> </body> </html> The PHP Code (form-process.php): <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "mar@gmail.com"; $email_subject = "Mario Business Contact"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['text'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $text = $_POST['text']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(strlen($text) < 2) { $error_message .= 'The text you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Jemand hat dir eine Nachricht vom Kontaktformular von mario.samirafracasso.com gesendet\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Vorname, Nachname: ".clean_string($name)."\n"; $email_message .= "Email Adresse: ".clean_string($email_from)."\n"; $email_message .= "Nachricht: ".clean_string($text)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); //RECAPTCHA if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) { if( isset ( $_POST['g-recaptcha-response'] ) && ! empty ( $_POST['g-recaptcha-response'] ) ) { $key = '6L1HtS8VIs'; $rip = 'htt'; $captchaurl = 'https://www.google.com/recaptcha/api/siteverify?'; $captchaurl .= 'secret=' . $key . '&'; $captchaurl .= 'response=' . $_POST['g-recaptcha-response'] . '&'; $captchaurl .= 'ip=' . $rip; $curl_init = curl_init (); curl_setopt ( $curl_init, CURLOPT_URL, $captchaurl ); curl_setopt ( $curl_init, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $curl_init, CURLOPT_TIMEOUT, 5 ); curl_setopt ( $curl_init, CURLOPT_USERAGENT, 'PHP/reCAPTCHA' ); curl_setopt ( $curl_init, CURLOPT_SSL_VERIFYPEER, FALSE ); $response = curl_exec ( $curl_init ); if ( $response == FALSE ) { echo '<p>Curl Error: ' . curl_error ( $curl_init ); } else { $result = json_decode ( $response, TRUE ); if($result['success']) { echo 'Recaptha Result: '; var_dump ( $result['success'] ); } } curl_close ( $curl_init ); } } ?> <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="../css/style.css"> <title>E-Mail versendet</title> </head> <body> <div id="mail-sent"> <h1>Thank you for contacting us. We will be in touch with you very soon.</h1> </div> </body> </html> <?php } ?> Thanks in advance for your help. Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 4, 2015 Share Posted November 4, 2015 (edited) My problem is, if a user fills out the form and forgets to use the captcha, the mail will be sent anyways..Whats the problem? Whats missing in my Code? Read my post(d) again from your other topic. I told you what to do but you ignored me. Also topic locked seeing as this is related to your your last topic Edited November 4, 2015 by Ch0cu3r Link to comment Share on other sites More sharing options...
Recommended Posts