1. Home
  2. Docs
  3. Gateway
  4. HTTP Api
  5. Script examples

Script examples

PHP Script

This simple script generates an HTML file with a form for sending SMS. When sending, the data is transferred to the HTTP Api and the return is evaluated.

 
<? if(!isset($_POST['submit'])){ ?>
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
        Recipient: <input name="to" type="text" /><br />
        SMS Type:
        <select name="type">
            <option>economy</option>
            <option>direct</option>
        </select><br />
        Sender ID: <input name="from" type="text" /><br />
        Message: <textarea name="text"></textarea><br />
        <input name="submit" type="submit" value="Send SMS!" />
    </form>
<? } else { 
    $params = array( 
        "p" => "api_key", 
        "to" => $_POST['to'], 
        "text" => $_POST['text'], 
        "type" => $_POST['type'], 
        "from" => $_POST['from'] 
    ); 
    $url = 'https://gateway.sms77.io/api/sms?' . http_build_query($params); 
 
    // Here the HTTP API is called by means of the HTTP GET Request 
    // The character @ is required, so that the URL isn't output in case of errors
    // If you do not receive a return, check if allow_url_fopen is enabled in your server
    //  More information here: http://php.net/manual/en/features.remote-files
    $ret = @file_get_contents($url); 
    $parts = explode("\n", $ret); 
 
    // SMS sent successfully
    if ($ret !== false && $parts[0] == "100") 
        echo "SMS sent successfully! ID: " . $parts[1]; 
 
    // Error code output 
    else 
        echo "An error occured: " . $ret; 
} ?>
Was this article helpful to you? Yes No
Menu