Snippets

Send SMS with PHP and Clickatell HTTP Api

Class example to get your balance, and to send an sms using the Clickatell API. No validation happens on the data you submit. This will need to be handled by you. (Maybe I’ll add extra code for that later)

<?php 

/* 
 * EnterSolutions 
 * @Author : Morne Oosthuizen (http://www.entersolutions.co.za) 
 *  
 */ 

class Communications 
{ 

    /* 
     * Send Sms 
     * @param         $aMsgData = array(Number,Message); 
     * @return      String 
     *  
     */ 
    public function SendSms($aMsgData) 
    { 
        $result = file_get_contents('http://api.clickatell.com/http/sendmsg?api_id='.CLICKATELL_API.'&user='.CLICKATELL_USERNAME.'&password='.CLICKATELL_PASSWORD.'&to='.$aMsgData['to'].'&text='.substr(urlencode($aMsgData['msg']),0,160));
        return $result; 
    } 
     
    /* 
    * Get available credits 
    *  
    * @return         String 
    *  
    */ 
    public function GetBalance() 
    { 
        $result = file_get_contents('http://api.clickatell.com/http/getbalance?api_id='.CLICKATELL_API.'&user='.CLICKATELL_USERNAME.'&password='.CLICKATELL_PASSWORD); 
        return $result; 
    } 
     

}

Share this snippet

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Please respect the following rules: No advertising, no spam, no keyword in name field. Thank you!