<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Text Marketer - Email SMS, Bulk SMS Gateway, SMS Marketing Blog &#187; php5</title>
	<atom:link href="http://www.textmarketer.co.uk/blog/tag/php5/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.textmarketer.co.uk/blog</link>
	<description>SMS Gateway</description>
	<lastBuildDate>Tue, 07 Feb 2012 09:50:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>REST SMS API Code Examples</title>
		<link>http://www.textmarketer.co.uk/blog/2010/03/dev/rest-sms-api-code-examples/</link>
		<comments>http://www.textmarketer.co.uk/blog/2010/03/dev/rest-sms-api-code-examples/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 10:56:58 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
				<category><![CDATA[All SMS Gateway Documentation]]></category>
		<category><![CDATA[Development Blog]]></category>
		<category><![CDATA[PHP Classes]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[sms api]]></category>
		<category><![CDATA[support]]></category>

		<guid isPermaLink="false">http://87.106.109.73/blog/?p=1157</guid>
		<description><![CDATA[This blog post has been superseded with our website documentation In our REST API specification document we saw, in general terms, how to make a request to our REST SMS API and how to deal with the response. Here we provide you with some more concrete examples that you can copy &#38; paste! &#8230; <a href="http://www.textmarketer.co.uk/blog/2010/03/dev/rest-sms-api-code-examples/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.textmarketer.co.uk/developers/restful-api.htm">This blog post has been superseded with our website documentation</a></p>
<p>In our <a title="REST SMS API specification" href="/blog/2010/03/business-sms/rest-sms-api-specification-document/" target="_self">REST API specification document</a> we saw, in general terms, how to make a request to our REST SMS API and how to deal with the response. Here we provide you with some more concrete examples that you can copy &amp; paste!</p>
<p>NOTE: You will want to add additional error checking to the examples below.</p>
<p>In each of the languages used here we create a request, send it, receive the response, and parse its contents.</p>
<p><strong>PHP</strong></p>
<p>Example for getting the number of credits:</p>
<pre>$url = 'http://www.textmarketer.biz/services/rest/credits';
$username = 'myAPIusername'; // CHANGE THIS!!!
$password = 'myAPIpassword'; // CHANGE THIS!!!
$url = "$url?username=$username&amp;password=$password";

// we're using the curl library to make the request
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
$responseBody = curl_exec($curlHandle);
$responseInfo  = curl_getinfo($curlHandle);
curl_close($curlHandle);

// deal with the response
if ($responseInfo['http_code']==200)
{
	$xml_obj = simplexml_load_string($responseBody);
	$credits = (int) $xml_obj-&gt;credits;
	// do something with the result
	echo $credits;

} else {
	// handle the error
	var_dump($responseBody);
}</pre>
<p>Example for getting the list of delivery reports:</p>
<pre>$url = 'http://www.textmarketer.biz/services/rest/deliveryReports';
$username = 'myAPIusername'; // CHANGE THIS!!!
$password = 'myAPIpassword'; // CHANGE THIS!!!
$url = "$url?username=$username&amp;password=$password";

// we're using the curl library to make the request
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
$responseBody = curl_exec($curlHandle);
$responseInfo  = curl_getinfo($curlHandle);
curl_close($curlHandle);

// deal with the response
if ($responseInfo['http_code']==200)
{
	$xml_obj = simplexml_load_string($responseBody);
	$atts = $xml_obj-&gt;reports-&gt;attributes();
	$num_reports = (int) $atts-&gt;quantity;

	if ($num_reports &gt; 0)
	{
		echo "$num_reports reports\n";
		$reports = array();
		foreach ($xml_obj-&gt;reports-&gt;report as $xml_report)
		{
			$atts = $xml_report-&gt;attributes();
			$name = (string) $atts-&gt;name;
			$updated = (string) $atts-&gt;last_updated;
			$reports[] = array('name'=&gt;$name, 'modified'=&gt;$updated);
		}
		// do something with the report details
		var_dump($reports);
	} else {
		echo 'No reports available';
	}
} else {
	// handle the error
	var_dump($responseBody);
}</pre>
<p>Example for getting the details of a particular delivery report:</p>
<pre>// TODO the URL will change according to the delivery report to retrieve...
$url = 'http://www.textmarketer.biz/services/rest/deliveryReport/GatewayAPI_09-02-10';
$username = 'myAPIusername'; // CHANGE THIS!!!
$password = 'myAPIpassword'; // CHANGE THIS!!!
$url = "$url?username=$username&amp;password=$password";

// we're using the curl library to make the request
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
$responseBody = curl_exec($curlHandle);
$responseInfo  = curl_getinfo($curlHandle);
curl_close($curlHandle);

// deal with the response
if ($responseInfo['http_code']==200)
{
	$xml_obj = simplexml_load_string($responseBody);

	$reportRows = array();
	foreach ($xml_obj-&gt;report-&gt;reportrow as $xml_reportRow)
	{
		$atts = $xml_reportRow-&gt;attributes();
		$mobile = (string) $atts-&gt;mobile_number;
		$updated = (string) $atts-&gt;last_updated;
		$msgID = (int) $atts-&gt;message_id;
		$status = (string) $atts-&gt;status;
		$reports[] = array('mobile'=&gt;$mobile, 'modified'=&gt;$updated, 'messageID'=&gt;$msgID, 'status'=&gt;$status);
	}
	// do something with the report details
	var_dump($reports);

} else {
	// handle the error
	var_dump($responseBody);
}</pre>
<p>Example for sending an SMS:</p>
<pre>$url = 'http://www.textmarketer.biz/services/rest/sms';
$username = 'myAPIusername'; // CHANGE THIS!!!
$password = 'myAPIpassword'; // CHANGE THIS!!!

$data = array('message'=&gt;'hello','mobile_number'=&gt;'447777777777', 'originator'=&gt;'me',
	'username'=&gt;$username, 'password'=&gt;$password);
$data = http_build_query($data, '', '&amp;');
// we're using the curl library to make the request
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $data);
curl_setopt($curlHandle, CURLOPT_POST, 1);
$responseBody = curl_exec($curlHandle);
$responseInfo  = curl_getinfo($curlHandle);
curl_close($curlHandle);

// deal with the response
if ($responseInfo['http_code']==200)
{
	$xml_obj = simplexml_load_string($responseBody);
	// do something with the result
	echo "Message ID: $xml_obj-&gt;message_id\n";
	echo "Credits used: $xml_obj-&gt;credits_used\n";

	var_dump($responseBody);

} else {
	// handle the error
	var_dump($responseInfo);
	var_dump($responseBody);
}</pre>
<p>Example for transferring credits:</p>
<pre>
<div>&lt;?php</div>
<div>/**</div>
<div> * POST request on the 'credits' resource (credit transfer)</div>
<div> */</div>
<div>$url = '<a href="http://www.textmarketer.biz/services/rest/credits" target="_blank">http://www.textmarketer.biz/services/rest/credits</a>';</div>
<div>// for testing:</div>
<div>//$url = '<a href="http://sandbox.textmarketer.biz/services/rest/credits" target="_blank">http://sandbox.textmarketer.biz/services/rest/credits</a>';</div>
<div>$username = 'myAPIusername'; // CHANGE THIS!!! - the username of the account you're transferring FROM</div>
<div>$password = 'myAPIpassword'; // CHANGE THIS!!!</div>
<div>$targetAccountNumber = 0; // CHANGE THIS!!</div>
<div></div>
<div>$data = array('quantity'=&gt;'1','target'=&gt;$targetAccountNumber,</div>
<div><span>	</span>'username'=&gt;$username, 'password'=&gt;$password);</div>
<div>$data = http_build_query($data, '', '&amp;');</div>
<div>// we're using the curl library to make the request</div>
<div>$curlHandle = curl_init();</div>
<div>curl_setopt($curlHandle, CURLOPT_URL, $url);</div>
<div>curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);</div>
<div>curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $data);</div>
<div>curl_setopt($curlHandle, CURLOPT_POST, 1);</div>
<div>$responseBody = curl_exec($curlHandle);</div>
<div>$responseInfo  = curl_getinfo($curlHandle);</div>
<div>curl_close($curlHandle);</div>
<div></div>
<div>// deal with the response</div>
<div>if ($responseInfo['http_code']==200)</div>
<div>{</div>
<div> // success - you may want to read in the return data here to see how many credits were  left on each account</div>
<div></div>
<div>} else {</div>
<div><span>	</span>// handle the error here</div>
<div><span>	</span>// var_dump($responseInfo);</div>
<div><span>	</span>// var_dump($responseBody);</div>
<div>}</div>

?&gt;</pre>
<p>For more details on creating <a title="REST requests in PHP" href="http://www.gen-x-design.com/archives/making-restful-requests-in-php/" target="_blank">REST requests in PHP, see here</a>.</p>
<img src="http://www.textmarketer.co.uk/wordpress/?ak_action=api_record_view&id=1157&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.textmarketer.co.uk/blog/2010/03/dev/rest-sms-api-code-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP 5 Delivery Report Helper Class for our SMS Gateway</title>
		<link>http://www.textmarketer.co.uk/blog/2009/06/sms-gateway/php-5-delivery-report-helper-class/</link>
		<comments>http://www.textmarketer.co.uk/blog/2009/06/sms-gateway/php-5-delivery-report-helper-class/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 10:16:51 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[All SMS Gateway Documentation]]></category>
		<category><![CDATA[PHP Classes]]></category>
		<category><![CDATA[delivery]]></category>
		<category><![CDATA[gateway]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[reporting]]></category>
		<category><![CDATA[sms]]></category>

		<guid isPermaLink="false">http://87.106.109.73/blog/?p=171</guid>
		<description><![CDATA[Class Name: ProcessDeliveryReport This class enables you to access your delivery reports in a nice simplified way. You can search for the outcome of a message for a given number, specify the outcome and the number, download all the data for the given date or parse the reports line by line. &#8230; <a href="http://www.textmarketer.co.uk/blog/2009/06/sms-gateway/php-5-delivery-report-helper-class/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Class Name: ProcessDeliveryReport</h2>
<p>This class enables you to access your delivery reports in a nice simplified way. You can search for the outcome of a message for a given number, specify the outcome and the number, download all the data for the given date or parse the reports line by line.</p>
<p>The constructor requires the delivery report directory that is shown in your account. To find your  delivery report directory, log into your system click the menu heading &#8220;Reports&#8221; then select &#8220;Delivery Reporting&#8221;, you will see a green icon, roll over this and you can find the directory name at the bottom.</p>
<p>If you have sent a message greater than 160 characters you will find multiple entries for that particular number . For instance if your message was 200 characters you will find 2 reports for that number. A message is built from 160 chunks</p>
<p>Download the <a href="http://www.textmarketer.co.uk/downloads/ProcessDeliveryReport.txt" target="_blank">PHP 5 Delivery Report Class</a></p>
<h2>Example of use</h2>
<pre>&lt;?

$reports = new ProcessDeliveryReport ( "Kt65CZMtxlIiEU328ilCBgC38" ); // your delivery report directory
if ($reports-&gt;setReportDate ( "20-05-09" )) print_r ( $reports-&gt;findNumber ( "44777777777", "r" ) ); // print the array of results
else echo "Not found";

?&gt;</pre>
<img src="http://www.textmarketer.co.uk/wordpress/?ak_action=api_record_view&id=171&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.textmarketer.co.uk/blog/2009/06/sms-gateway/php-5-delivery-report-helper-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP 5 SMS Send Class implementing listeners on our SMS Gateway</title>
		<link>http://www.textmarketer.co.uk/blog/2009/06/sms-gateway/php-5-sms-send-class-implementing-listeners/</link>
		<comments>http://www.textmarketer.co.uk/blog/2009/06/sms-gateway/php-5-sms-send-class-implementing-listeners/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 08:33:07 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[All SMS Gateway Documentation]]></category>
		<category><![CDATA[PHP Classes]]></category>
		<category><![CDATA[gateway]]></category>
		<category><![CDATA[listener]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[sms]]></category>

		<guid isPermaLink="false">http://87.106.109.73/blog/?p=167</guid>
		<description><![CDATA[Class Name: SendSMSNotifier This class is designed around the FREE Text Marketer SMS API, you need to sign up here to use it. SendSMSNotifier is a singleton class design, incorporating listeners. Your class must include the following public functions: creditAlert($credits_remaining) and failureAlert($error,$number,$message,$error). Download the class from here Example of use &#8230; <a href="http://www.textmarketer.co.uk/blog/2009/06/sms-gateway/php-5-sms-send-class-implementing-listeners/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Class Name: SendSMSNotifier</h2>
<p>This class is designed around the FREE Text Marketer SMS API, you need to sign up here to <a href="http://www.textmarketer.co.uk/free-bulk-sms-software.htm" target="_blank">use</a> it.</p>
<p>SendSMSNotifier is a singleton class design, incorporating listeners. Your class must include the following public functions: creditAlert($credits_remaining) and failureAlert($error,$number,$message,$error).</p>
<p>Download the class from <a href="http://www.textmarketer.co.uk/downloads/SendSMSNotifier.txt" target="_blank">here</a></p>
<h2>Example of use</h2>
<pre>class MyTestClass
{</pre>
<pre>        /// simple array of data in: number, message, sender Id (aka originator) format, ideally the data will come from a database
	private $mySMSdata = array(array("44777777777","Hello World!","Me"),
			                             array("text","This will throw an error, mobile number is text","Me"));

	function __construct()
	{
		$sms = SendSMSNotifier::getInstance("myUsername","myPassword"); // your account login details
		$sms-&gt;addListener($this); // Your class gets added to the listeners that will get notified on an event
		$sms-&gt;setCreditThreshold(5); // You want o be notified when you have 5 credits left

		foreach($this-&gt;mySMSdata as $record) // send some data
		{
			list($number,$message,$sender) = $record;
			$sms-&gt;send($number,$message,$sender); // send to the api
		}
		echo $sms-&gt;getCredits();
		print_r($this-&gt;errors);
	}

	public function failureAlert($error,$number,$message,$originator)
	{
		/// Required function for failure messages, you could stop the sending here or log the results
		$this-&gt;errors[] = array($error,$number,$message,$originator);
	}

	public function creditAlert($credits)
	{
		/// Required function for credit alerts, this basic implementation stops sending anymore SMS's
		die("I have nearly run out of credits($credits left), abandon sending!");
	}
}</pre>
<p>So here&#8217;s what happens. You send a bunch of text messages to the gateway using your class (in this example MyTestClass), if you get a failure such as a badly formatted number your function <strong>failureAlert</strong> gets called with the parameters of the failure and data, you can then decide on the implmentation. In the above example it just stores them in an array, once you have sent all the data you could then use the data to clean your database etc.</p>
<p>If the credit limit (in the above case this is 5 $sms-&gt;setCreditThreshold(5) ) your function <strong>creditAlert</strong> will get called, in this case we think this is bad so we use the hammer of the <strong>die()</strong> function to stop the sending, obviously you would handle this much more elegantly :-)</p>
<img src="http://www.textmarketer.co.uk/wordpress/?ak_action=api_record_view&id=167&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.textmarketer.co.uk/blog/2009/06/sms-gateway/php-5-sms-send-class-implementing-listeners/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

