<?php
include("smsdb-conf.php");
require "sms/Services/Twilio.php";

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
	
	$sSql='SELECT * FROM wsoftsms_out 
		   WHERE status="U"';
	
	$result = mysql_query($sSql) or die(mysql_error());
	
	if(mysql_num_rows($result))
	{
		$client = new Services_Twilio($AccountSid, $AuthToken);

		while($aSms = mysql_fetch_array($result,MYSQL_ASSOC))
		{
			$people = array(
				"(415)6399480" => "Paul",
			);
	
			$body = "Good news $name, like working";

			try
			{
				$response = $client->account->sms_messages->create($from, $aSms['recipient'], $aSms['text']);
				$sSql='UPDATE wsoftsms_out SET status="S" WHERE id='.$aSms['id'];
	
			}
			catch (Exception $e)
			{
				$sSql='UPDATE wsoftsms_out SET status="E",error_message="'.$e->getMessage().'" WHERE id='.$aSms['id'];
			}
			
			mysql_query($sSql);
		}		
	}
?>