<?php
//prepare data
$url = 'http://www.smsapi.si/poslji-sms';            //url we are posting to (defined in sms api documentation)
$data = array('un' => urlencode('api_username'),     //api username
              'ps' => urlencode('api password'),     //api pass
              'from' => urlencode('031492148'),      //don't send as int
              'to' => urlencode('040859974'),        //don't send as int
              'm' => urlencode('Testno sporocilo'),  //msg
              'cc' => urlencode('386')               //don't send as int 
             );
             
############ SEND SMS WITH GET ###############
$url = $url . http_build_query($data);
$response = file_get_contents($url);
echo $response;




########### SEND SMS WITH POST ###############

//send SMS
$response  = doPostRequest($url, $data);
echo($response);


/**
 * Posts $data on $url and returns content of website
 * POST request was made to.
 * 
 * @param $url - url where we are posting data
 * @param $data - array with key => value pairs for post 
 *                e.g. array('un' => 'example', 'ps' => 'pass', ...)
 *
 * @return string
 */
function doPostRequest($url, $data) {
    // Initialisation
    $ch=curl_init();
    
    // Set parameters
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);

    // Activate the POST method
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1) ;
    
    // Request
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    
    // execute the connexion
    $result = curl_exec($ch);
    
    // Close it
    curl_close($ch);
    
    return $result;
}