PHP fopen SMS API Script

PHP fopen SMS API Script

Develop SMS API using PHP fopen

This is just an example Bulk SMS API code for PHP fopen, please make sure to sanitize data and other security aspects at the time of real development.

Send Bulk SMS using PHP fopen

Sample scripts are provided just for reference only, do not develop using the same code.

Download Text File

<?php
    //PHP FOPEN API SAMPLE
    //You need to change your settings below.
    //https://www.smsgatewaycenter.com/library/send_sms_2.php?UserName=username&Password=password&Type=Individual&To=9999999999&Mask=Senderid&Message=Hello%20World
    //---------------------------------
    $username = "myusername";
    $mypassword = "mypassword";
    $sendername = "mysendername";
    $domain = "www.smsgatewaycenter.com/library/";
    //API Domain
    $type = "Individual";
    //Individual/Bulk/Group
    $lang = "English";
    //English/Other - Default is English
    $method = "POST";
    //---------------------------------
    
    if(isset($_REQUEST['send']) && $_REQUEST['send'] == 'Send'){
        $mobile = $_REQUEST['mobile'];
        $message = $_REQUEST['message'];
        //sanitize inputs
        $username = urlencode($username);
        $password = urlencode($password);
        $sendername = urlencode($sendername);
        $message = urlencode($message);

        $parameters = "UserName=".$username."&Password=".$mypassword."&Type=".$type."&To=".$mobile."&Mask=".$sendername."&Message=".$message."&Language=".$lang;
        $apiurl = "https://".$domain."/send_sms_2.php";
        $ch = curl_init($apiurl);
       
        if($method == "POST"){
            $opts = array(
                        'http'=>array(
                            'method'=>"$method",
                            'content' => "$parameters",
                            'header'=>"Accept-language: en\r\n"
                                    . "Cookie: foo=bar\r\n"
                            )
                        );
            $context = stream_context_create($opts);
            $fp = fopen($apiurl, "r", false, $context);
        } else {
            $fp = fopen($apiurl."?".$parameters, "r");
        }

        curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
        curl_setopt($ch, CURLOPT_HEADER,0);
        // DO NOT RETURN HTTP HEADERS
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        // RETURN THE CONTENTS OF THE CALL
        $return_val = curl_exec($ch);
       
        if($return_val=="")echo "Process Failed, Please check domain, username and password."; else echo $return_val;
    }

    echo "<form name='form1' method='post'>";
    echo "<p> Mobile: <input name='mobile'></p>";
    echo "<p> Message: <textarea name='message'></textarea></p>";
    echo "<p> <input type='submit' value='Send' name='send'></p>";
    echo "</form>";
    ?>

Go Back! SMS Developers API

Save this interesting page on your Favorite Social Media

Premium Bulk SMS Gateway

SMS Pricing

Receive a Call

Services

SMS Business Opportunities

Bulk SMS Know-how


Convinced? Get an estimate. Contact Now!