Shivaanant Posted January 8, 2017 Share Posted January 8, 2017 (edited) Hi Experts... I enabled google recaptcha for my email form, as i was getting tons of bot blank emailform. Now captcha work fine, but i am unable to get filled value in my email - back from the form. PS: This is a new script i collected from 2-3 sources and did some editing (I am a graphics guy, so maybe missed any point) Tried to debug many times, but no luck. Help much appreciated. Thanks in advance. <?php if(isset($_POST['submit'])): if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])): //your site secret key $secret = 'mygooglescretkey'; //get verify response data $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']); $responseData = json_decode($verifyResponse); $name = !empty($_POST['name'])?$_POST['name']:''; $email = !empty($_POST['email'])?$_POST['email']:''; $message = !empty($_POST['message'])?$_POST['message']:''; if($responseData->success): //contact form submission code $to = "info@mydomain,com, mysecondaryemail@gmail.com"; $subject = 'Naming Form via Website'; $email_from = 'info@mydomain,com'; //!-- >mail($mailto,$subject,$message_body,"From:".$from); $htmlContent = " <h1>Contact request details</h1> <p><b>Name: </b>".$name."</p> <p><b>Email: </b>".$email."</p> <p><b>Message: </b>".$message."</p> "; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers .= 'From:'.$name.' <'.$email.'>' . "\r\n"; //send email mail($to,$subject,$html_Content,$headers,"From:".$email_from); $succMsg = 'Your contact request have submitted successfully.'; $name = ''; $email = ''; $message = ''; $to = ''; $from = ''; $headers = ''; header('Location: http://www.mydomain.com/thankyou.htm'); else: $errMsg = 'Robot verification failed, please try again.'; endif; else: $errMsg = 'Please click on the reCAPTCHA box.'; endif; else: $errMsg = ''; $succMsg = ''; $name = ''; $email = ''; $message = ''; $to = ''; $from = ''; $headers = ''; endif; ?> <html> <head> <title>Using new Google reCAPTCHA with PHP by CodexWorld</title> <script src="https://www.google.com/recaptcha/api.js" async defer></script> <link href="css/style.css" rel='stylesheet' type='text/css' /> </head> <body> <div class="registration"> <h2>Contact Form</h2> <div class="avtar"><img src="images/color.jpg" /></div> <?php if(!empty($errMsg)): ?><div class="errMsg"><?php echo $errMsg; ?></div><?php endif; ?> <?php if(!empty($succMsg)): ?><div class="succMsg"><?php echo $succMsg; ?></div><?php endif; ?> <div class="form-info"> <form action="" method="POST"> <input type="text" class="text" value="<?php echo !empty($name)?$name:''; ?>" placeholder="Your full name" name="name" > <input type="text" class="text" value="<?php echo !empty($email)?$email:''; ?>" placeholder="Email adress" name="email" > <textarea type="text" placeholder="Message..." required="" name="message"><?php echo !empty($message)?$message:''; ?></textarea> <div class="g-recaptcha" data-sitekey="mygooglescretcode"></div> <input type="submit" name="submit" value="SUBMIT"> </form> </div> <div class="clear"> </div> </div> </body> </html> Edited January 8, 2017 by Barand code tags added Quote Link to comment https://forums.phpfreaks.com/topic/302890-php-code-fix-help/ Share on other sites More sharing options...
Barand Posted January 8, 2017 Share Posted January 8, 2017 Do not post multiple copies of the same problem. Quote Link to comment https://forums.phpfreaks.com/topic/302890-php-code-fix-help/#findComment-1541177 Share on other sites More sharing options...
bsmither Posted January 10, 2017 Share Posted January 10, 2017 You probably have an error in these statements: $to = "info@mydomain,com, mysecondaryemail@gmail.com"; $subject = 'Naming Form via Website'; $email_from = 'info@mydomain,com'; Check the spelling of the email addresses. Quote Link to comment https://forums.phpfreaks.com/topic/302890-php-code-fix-help/#findComment-1541245 Share on other sites More sharing options...
mac_gyver Posted January 10, 2017 Share Posted January 10, 2017 the OP does have a spelling mistake, but it's in the variable name being used to hold the message body. if you had php's error reporting set to E_ALL and display_errors set to ON, php would help you by reporting and displaying all the errors it detects. next, I'm surprised you are receiving any emails. the 5th parameter of the mail() function is not in the format of 'From: email', if it's used to supply the sending email address, the format is '-femail' and these emails are NOT being sent from the email address that someone entered in a form on your web site and using it as the From: email header is not correct. the line building the email header - $headers .= 'From:'.$name.' <'.$email.'>' . "\r\n"; should not be using the submitted email address. you can put the submitted email address as a Reply-to: $email email header, after validating that the value in $email is only and exactly one properly formatted email address. Quote Link to comment https://forums.phpfreaks.com/topic/302890-php-code-fix-help/#findComment-1541249 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.