Janell Posted April 2, 2018 Share Posted April 2, 2018 I am submitting an email form that posts to a php page. The form is being sent, I'm receiving the email but I am getting "The page cannot be displayed because an internal server error has occurred." message rather than the landing/success page. I needed to update the reCAPTCHA on the site. The only thing I've changed/added in the code is the part at the bottom, starting at $url. I'm not familiar with php, any help would be appreciated. <?php $email = "email@email.com"; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = "Online Contact Form"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"Company"} = "Company"; $fields{"Question"} = "Message"; $body = "We have received a new submission from the Contact form\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } if($from == '') {print "You have not entered an email, please go back and try again";} else { if($name == '') {print "You have not entered a name, please go back and try again";} else { $send = mail($email, $subject, $body, $headers); if($send) {echo "Thank you! Your email has been sent.<br> We will get back to you as soon as we can. <br> <a href='http://www.home/index.html'>Go to Home</a>"; } else {print "We encountered an error sending your mail, please notify webmaster@website.com."; } } } $url = 'https://www.google.com/recaptcha/api/siteverify'; $data = array( 'secret' => 'xyz', 'response' => $_POST["g-recaptcha-response"] ); $options = array( 'http' => array ( 'method' => 'POST', 'content' => http_build_query($data) ) ); $context = stream_context_create($options); $verify = file_get_contents($url, false, $context); $captcha_success = json_decode($verify); ?> Quote Link to comment Share on other sites More sharing options...
dodgeitorelse3 Posted April 2, 2018 Share Posted April 2, 2018 Shouldn't they be square brackets at $fields instead of curly braces? Quote Link to comment Share on other sites More sharing options...
Janell Posted April 2, 2018 Author Share Posted April 2, 2018 Thanks, I changed those to brackets. I am still getting the error and still receiving the email. Quote Link to comment Share on other sites More sharing options...
Ofarchades Posted April 2, 2018 Share Posted April 2, 2018 I'm guessing the reCAPTCHA code should come before the mail is sent - and that you need to check the result to make sure it validated before sending the email. As for the error, there could be so many reasons. Maybe your server is configured to not allow URLs to be passed to file_get_contents? Maybe $_POST["g-recaptcha-response"] isn't set (did you add it to your form?). Maybe there's some reason file_get_contents is taking too long to load the URL (bad connection to the server, the server is blocking the request, etc) and the script is timing out? That last one will be easy to rule out depending on whether you get the error quickly or if the page loads for ~30 seconds or so. Quote Link to comment Share on other sites More sharing options...
Solution Janell Posted April 3, 2018 Author Solution Share Posted April 3, 2018 Thanks! Turns out, I was missing something (php_openssl.dll extension was commented out) in my php ini. It works now. Quote Link to comment 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.