-1

This is my index.html (form):

<div class="body"> 
    <form method="post" action="index.php">
        <div id="form"> 
            <div class="formInput"> 
                <label>To: 
                <input type="text" name="to" id="to" /> 
                </label> 
            </div> 
            <div class="formInput"> 
                <label>From: 
                <input type="text" name="from" id="from" /> 
                </label> 
            </div> 
            <div class="formInput"> 
                <label>Message: 
                <input type="text" name="message" id="message" /> 
                </label> 
            </div>
            <input type="submit" value="Submit" /> 
            <input type="reset" value="Clear Form" /> 
        </div> 
    </form>

And this is the index.php that handles the data:

<?php
$url = 'https://domainname.com/dashboard/api';
$r = new HttpRequest($url, HttpRequest::METH_POST);
$r->addQueryData(array('to' => $_POST['to'],
                       'from' => $_POST['from'],
                       'email' => $email,
                       'api_secret' => $api_secret));
try {
    $r->send();
    if ($r->getResponseCode() == 200) {
        echo $r->getResponseBody();
    }
} catch (HttpException $ex) {
    echo $ex;
}
?>

Everytime i sumbit to the form i get an error: "PHP Fatal error: Class 'HttpRequest' not found" I have no idea how to resolve this since im running this on my namecheap web server.. A few people suggested i use cURL but i absolutely have no idea how.. I spent the past 3 hours trying to understand and i made zero progress.

Note:This how the http request should look like, i don't even know if i'm doing it correctly...

https://domainname.com/dashboard/api
?to={PHONE NUMBER}&from={SENDER ID}&message={TEXT}
&email={YOUR EMAIL}&api_secret={API SECRET}
hopw Jan
  • 39
  • 5
  • PHP has no HttpRequest class, where did you get that from? Seems like you found an example that's using a framework of some kind. – El_Vanja Mar 03 '20 at 23:15
  • Is it possible to switch to curl? – hopw Jan Mar 03 '20 at 23:19
  • Anything should be possible. Check out [this question](https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code) for a simple example. – El_Vanja Mar 03 '20 at 23:34

1 Answers1

1

HttpRequest is a class only available from pecl

If you wish to use this class, you'll need to install pecl on your server. Since you're using a namecheap server, it's unlikely that you'll be able to do this.

As has been mentioned in some comments, I'd suggest looking at using cURL. For example, you could do something like this:

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://domainname.com/dashboard/api',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => [
        'to' => $_POST['to'],
        'from' => $_POST['from'],
        'email' => $email,
        'api_secret' => $api_secret,
    ],
]);

$response = curl_exec($ch);

curl_close($ch);

echo($response);

See the documentation here.

CountKyle
  • 459
  • 3
  • 15