<?php

function Send_Message($username,$password,$phone_number,$message,$mobiles_array)
{
  $url = "http://smspanel.trez.ir/api/smsAPI/SendMessage";
  $post_data = json_encode(array(
    'PhoneNumber' => $phone_number,
    'Message' => $message,
    'Mobiles' => $mobiles_array,
    'UserGroupID' => uniqid(),
    'SendDateInTimeStamp' => time(),
  ));
  
  $process = curl_init();
  curl_setopt($process,CURLOPT_URL,$url);
  curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
  curl_setopt($process, CURLOPT_TIMEOUT, 30);
  curl_setopt($process, CURLOPT_POST, 1);
  curl_setopt($process, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
  curl_setopt($process, CURLOPT_POSTFIELDS, $post_data);                                                                 
  curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($process, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($process, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json'));   
    
    $return = curl_exec($process);
    $httpcode = curl_getinfo($process, CURLINFO_HTTP_CODE);
        // print_r($post_data);
    if($httpcode==401)
    {
      throw new exception("نام کاربری یا کلمه عبور صحیح نمی باشد");
    }
    curl_close($process);
    $decoded = json_decode($return);

    //  print_r($decoded);
    return $decoded;
  }

?>