1

Here is the issue. I am trying to troubleshoot an issue in my PHP script that prevents it from emailing the info, our client has inputted.

<?php    
session_start();    
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$recaptcha=$_POST['g-recaptcha-response'];
if(!empty($recaptcha))
{
include("getCurlData.php");
$google_url="https://www.google.com/recaptcha/api/siteverify";
$secret='6LegpgYTAAAAABK9Nd45_DfAPu7_gwHro9pj902B';
$ip=$_SERVER['REMOTE_ADDR'];
$url=$google_url."?secret=".$secret."&response=".$recaptcha."&remoteip=".$ip;
$res=getCurlData($url);
$res= json_decode($res, true);
//reCaptcha success check
if($res['success'])
{

  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

  if(isset($_POST['submit'])) {
  $to = "[email protected]";
  $subject = "New opinion post";

  // data the visitor provided
  $name_field = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
  $phone_field = filter_var($_POST['number']);
  $address_field = filter_var($_POST['address'], FILTER_SANITIZE_STRING);
  $comment = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);

  //constructing the message
  $body = "
  From: $name_field <br/>
  Email Address: $address_field <br/>
  Phone number: $phone_field <br/>
  Message:<br/> $comment ";

  // ...and away we go!
  mail($to, $subject, $body, $headers);

  // redirect to confirmation
  header("Location: confirmation2.html");
  }

  else {
  // handle the error somehow
  echo "Error accessing the file";
  }

  }
  else
  {
  echo "Въвели сте грешен код за потвърждаване (reCAPTCHA)! Натиснете "назад" и опитайте отново";
  }

  }
  else
  {
  echo "Не сте въвели код за потвърждаване (reCAPTCHA)! Натиснете "назад" и опитайте отново";
  }
 }

  ?>

worse thing is , it used to work , then I opened it, edited some stuff and now it doesnt work, tried the back-up copy and it still doesnt work !? Working in CMS MadeSimple. the URLs are correct , the confirmation2.html is a file, not a page made in CMS and it is in the same folder as the php script and if I try to access it directly (not via the contact from) its there, I have tried ' ' and " " quotes, still no change.

Probably a simple mistake, I did try looking for other solutions in here (stackoverflow.com) but nothing to fix my current issue. I know that I shouldnt have any output before the header but... well I dont have any output so, I'm baffled. Appreciation in advance to those who want to help!

4
  • You've forgotten an exit(); after redirecting with header("Location: confirmation2.html"); Commented Jul 10, 2015 at 11:39
  • Added , doesnt work :/ used to be ok without it before !? Commented Jul 10, 2015 at 11:50
  • Use header("Location: /uploads/doc/Online_Request/confirmation2.html"); exit(); If it still doesn't work (whatever doesn't work might mean btw) then make sure the execution of your code steps in this case if($res['success']) Commented Jul 10, 2015 at 11:53
  • ' doesn't work ' means I get a blank page, as if I have tried to open the script directly and not thru the form. And yes it still ' doesn't work ' ... also I don't have knowledge of how to troubleshoot and debug the code. Commented Jul 10, 2015 at 12:05

1 Answer 1

1

UPDATE: Seems like the reCAPTCHA was shitting me, and after I removed it - WORKS. Gonna leave it defenseless for now. Thanks to all who wanted to help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.