Rahul Mukati
Rahul Mukati

Reputation: 734

Getting 400 Bad Request in cUrl - PHP

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;
    ?>

Upvotes: 6

Views: 18033

Answers (1)

Ad5001
Ad5001

Reputation: 753

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

Upvotes: 22

Related Questions