PHP Clickatell Class

/**
 * @author Webarto
 * @copyright 2011
 */

class SMS{
    
    var $user = "webarto";
    var $password = "";
    var $api = "";
    var $url = "http://api.clickatell.com";
    
    public function send($to, $text){
        $auth = $this->curl($this->url."/http/auth?user=".$this->user."&password=".$this->password."&api_id=".$this->api);
        $auth = explode(":", $auth);
        if($auth[0] == "OK"){
            $text = trim($text);
            $text = urlencode($text);
            $text = substr($text, 0, 160);
            
            $status = $this->curl($this->url."/http/sendmsg?user=".$this->user."&password=".$this->password."&api_id=".$this->api."&to=$to&text=$text");
            $status = explode(":", $status);
            if($status[0] == "ID"){
                return "Message SENT!";
            }else{
                return "Message NOT SENT!";    
            }
        }else{
            return "Authentication FAILED!";
        }
               
    }

    private function curl($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        return curl_exec($ch);
        curl_close($ch);
    }      

}
©2009-2011 Webarto • web design & development • Tuzla // Sarajevo // Beograd