<?php
// Get the PHP helper library from twilio.com/docs/php/install


 function sendSMS($phone,$message){
//,$countryCode="gh"
	
  //$message = urlencode($message); 	
  //$phone   = urlencode($phone);
	
  twillo('+233243056828','Message: '.$message.' Phone: '.$phone);
  
	
  if(substr($phone, 3) == "+44"){

    $phone1 = trim("+44").substr($phone, -10);
    return twillo($phone1, $message);

  }elseif(substr($phone, 4) == "+233"){

    $phone1 = trim("+233").substr($phone, -9);  
	return twillo($phone1, $message);
	  
  }elseif(substr($phone, 4) == "+231"){

    $phone1 = trim("+231").substr($phone, -9);  
	return twillo($phone1, $message);
	  
  }elseif(substr($phone, 2) == "+1"){

    $phone1 = trim("+1").substr($phone, -10);  
	return twillo($phone1, $message);
  }else{
		//$phone = $phone;
		$phone_len = strlen($phone);
		$phone_sbst = substr($phone,0,1);
	  $phone1 = trim("+1").substr($phone, -10);
		if($phone_sbst=="0" && ($phone_len == "11")){
	return twillo($phone1, $message); 
			
		}else{
	return twillo($phone, $message);		
		}
  }
}



 function twillo($phone,$message){
	 
	  $source  = "PG Sterling"; urlencode("PG-Sterling");
	 //'+14844168086'

  $curl = curl_init();

  curl_setopt_array($curl, array(
	CURLOPT_URL            => 'https://api.twilio.com/2010-04-01/Accounts/AC8b0c35d935690b85fa749382ef00bd1f/Messages.json',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING       => '',
    CURLOPT_MAXREDIRS      => 10,
    CURLOPT_TIMEOUT        => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => array('Body' => $message,'From' => $source,'To' => $phone),
    CURLOPT_HTTPHEADER     => array(
      'Authorization: Basic QUM4YjBjMzVkOTM1NjkwYjg1ZmE3NDkzODJlZjAwYmQxZjpmZGY3MmM2ZWNkZDYyN2EyNmFlNzEyNzZmMDkxODcyYQ=='
    ),
  ));
  
  $response = curl_exec($curl);
  
  curl_close($curl);
  //echo $response;
  return true;

/******
  $source  = urlencode("PG Sterling");

  $curl = curl_init();

  curl_setopt_array($curl, array(
    CURLOPT_URL            => 'https://api.twilio.com/2010-04-01/Accounts/AC020a305fa3d0478155fc2ae875cbe705/Messages.json',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING       => '',
    CURLOPT_MAXREDIRS      => 10,
    CURLOPT_TIMEOUT        => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => array('Body' => $message,'From' => '+447888866613','To' => $phone),
    CURLOPT_HTTPHEADER     => array(
      'Authorization: Basic QUMwMjBhMzA1ZmEzZDA0NzgxNTVmYzJhZTg3NWNiZTcwNTpiYTIyZTVjYzA5NzM2YzU2ODEyZDJiMzM5MmY4OThlMQ=='
    ),
  ));
  
  $response = curl_exec($curl);
  
  curl_close($curl);
  //echo $response;
  return true;
**/
  
}



 function txtmategh($phone,$message){

        $source  = urlencode("Diamond-Pay");

        $message = urlencode($message);     
        //$source = urlencode("RentControl");
        $phone = urlencode($phone);
        
        $phone1 = trim("233").substr($phone, -9);
        
        
        $URL= "https://apps.txtmategh.com/sms/api?action=send-sms&api_key=d3pqa0R2S0pycUZLYj1QYXJMYnU=&to=".trim($phone1)."&from=".trim($source)."&sms=".trim($message);
        
        $ch = curl_init();
        
        curl_setopt($ch, CURLOPT_URL, $URL);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return response text
        
         $response = curl_exec ($ch);
        
        curl_close($ch);
            
            //return $response;
            
            //return true; 
            
       return true;      
}

