6

I am running the following code and getting this error:

Bad Request

Your browser sent a request that this server could not understand.

Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.

    <?php
      $phone = "1236547895";
      $message = 'Dear '.$firstname.' '.$lastname.',

Your invoice (#'.$invoiceid.') is successfully paid on '.$datepaid.' at Hostomy. Thank you for choosing us.

Regards,
Hostomy
';
      $url = "https://www.example.com/file.php?phone=".$phone."&message=".$message."";
      $ch = curl_init();
      $timeout = 10;
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
      $data = curl_exec($ch);
      curl_close($ch);
      return $data;
    ?>
5
  • Try defining $phone and $message. Commented Feb 15, 2017 at 18:24
  • added in question. Commented Feb 15, 2017 at 18:28
  • Have you got the open_ssl php5 extension installed? This could matter for HTTPS. Commented Feb 15, 2017 at 18:34
  • If i "echo $url" then it will show full $url very fine but not working with cURL. Commented Feb 15, 2017 at 18:35
  • If you copy/paste the $url directly in your browser, it works? Commented Feb 15, 2017 at 19:41

1 Answer 1

22

Try urlencode the message and the $phone vars :
$url = "https://www.example.com/file.php?phone=".urlencode($phone)."&message=".urlencode($message)."";

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

2 Comments

Phew. A life saver +1
Saved another hour.

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.