<?php
function sendMessage($to,$text='') {

	//$text = (string)$text;

	$curl = curl_init();

	curl_setopt_array($curl, array(
	  CURLOPT_URL => 'https://api.ycloud.com/v1/sms/send_messages',
	  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 =>'
	{
		 "mobile": "'.$to.'",
		 "text": "'.$text.'"
	}
	',
	  CURLOPT_HTTPHEADER => array(
		'Accept: application/json',
		'Content-Type: application/json',
		'X-API-Key: e095384349aac99c5b0690490a57cac3',
		//'Cookie: JSESSIONID=3FCFCDF40E18B0CC5809B9836A3DD641'
	  ),
	));
	
	$response = curl_exec($curl);
	
	curl_close($curl);
	file_put_contents('response.txt', $text . PHP_EOL, FILE_APPEND);
	file_put_contents('response.txt', json_encode($response) . PHP_EOL, FILE_APPEND);

	 //print_r(json_decode($response ,true));
	
	  //exit;
	//echo $response;

// 	echo $response;exit;
// $curl = curl_init();
// curl_setopt_array($curl, array(
//   CURLOPT_URL => 'https://api.ycloud.com/v1/sms/send_messages',
//   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 =>'{"mobile":"'.$to.'" ,"text":'.(string)$text.'}',
//   CURLOPT_HTTPHEADER => array(
//     'X-API-Key: d255424c52a8316d797b7a92a238b522',
//     'Content-Type: application/json',
// 	'Accept: application/json'
//     //'Cookie: JSESSIONID=8E09B09FAE717DE430990E6C30EF8B28'
//   ),
// ));
// $response = curl_exec($curl);
// curl_close($curl);
// echo $response;
// exit;
}



// // Required if your environment does not handle autoloading
//require __DIR__ . '/vendor/autoload.php';

// Use the REST API Client to make requests to the Twilio REST API
//use Twilio\Rest\Client;
// function sendMessage($to,$text='') {

	// $basic  = new \Vonage\Client\Credentials\Basic("ba1d4f0e", "eCVcE9dctSBlpAlm");
	// $client = new \Vonage\Client($basic);
	// $response = $client->sms()->send(new \Vonage\SMS\Message\SMS($to, 'INotify', $text));
	// $message = $response->current();
	// if ($message->getStatus() == 0) {
	   // // echo "The message was sent successfully\n";
	// } else {
		// echo "The message failed with status: " . $message->getStatus() . "\n";
	// }
	
	// // Your Account SID and Auth Token from twilio.com/console
	// $sid = 'AC7cd1228a827ef8d82f4f23bb202097bf';
	// $token = 'f03d3aa91c60902fbd20b68301f5b15a';
	
	// $client = new Client($sid, $token);
	// // Use the client to do fun stuff like send text messages!
	// $client->messages->create(
		// // the number you'd like to send the message to
		// //'+923230439099',
		// $to,
		// [
			// // A Twilio phone number you purchased at twilio.com/console
			// //'from' => '+447897025576',
			// 'from' => '+447888865970',
			// // the body of the text message you'd like to send
			// 'body' => $text
		// ]
	// );
//}