A CakePHP Component for the Servage SMS API
Say it with an automated text message.
Tagged with Servage, CakePHP and Web Development
Posted on 4/6/07 by Paul Herron
Being a Servage customer, I'm using its SMS API, which offers two main features:
- Check if a text message can be sent to a specified number.
- Send a text message to a specified number.
Servage provides some example code for doing this, which I've rewritten as a CakePHP component.
app/controllers/components/sms.php
<?php class SmsComponent extends Object { // The Servage URL for posting messages. var $send_url = 'http://smsgateway.servage.net/sms.php'; // The Servage URL for requesting coverage information. var $coverage_url = 'http://smsgateway.servage.net/sms_coverage.php'; // Customer ID. var $customer = '00000'; // Customer key. var $key = '00000000'; /** * Sends an SMS message to the specified number. * * @param int $to The phone number to which the message should be sent. * @param mixed $message The message to be sent. * @param mixed $from The name or number of the sender. * @param int $concat The number of messages to join when sending. * @return boolean True if the message was successfully posted to Servage. */ function send($to,$message,$from = null,$concat = 1) { // Add the parameters to the request URL. $request .= '&from=' . $from; // Make the request. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); // Get the status from the response string. if ($result[0] == 'OK') return true; } /** * Checks if coverage can be provided for the specified number. * * @param int $number The phone number with international dialling code, e.g. 447796544789. * @return boolean True if the specified number has coverage. */ function hasCoverage($number) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->coverage_url . '?number='.$number); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); if ($result[0] == 'OK') return true; } } ?>
Once the component is declared in the $components array of the controller, it can be used like this:
// Check coverage. $this->Sms->hasCoverage('447736044651'); // Send a message. $this->Sms->send('447736044651', 'This is a test message.')); // Send a message, this time specifying the sender and span. $this->Sms->send('447736044651', 'This is a second test message.', 'graemegarden', 2));
Comments
Leave a Comment
Article Tags
Show all articles, or just those tagged as:
- Apache (1)
- CakePHP (10)
- Domains (1)
- Freeware (1)
- Graphics (1)
- Life (1)
- Open Source (2)
- Servage (1)
- SMS (1)
- Software (3)
- Ubuntu (2)
- WAMP (2)
- Web Development (13)
- Windows (2)
- Work (2)
Feed
The articles RSS feed is available.
Elsewhom
-
Cool Hunting.
Finding things in the intersection of design, culture and technology that excite the imagination and inspire creativity -
A List Apart.
Influential webzine for web designers -
RichardHerring.com.
Home of the comedian and online journal-keeper - indexed.
-
Snook.ca.
Home of web developer Jonathan Snook

Jaylin wrote on 26/8/11:
AKAIK you've got the ansewr in one!nblffk wrote on 26/8/11:
uHiyGO wcoytpygqxofMommabits wrote on 28/8/11:
zovirax 8-PP gambling nexium mhmvuboffice2010key wrote on 16/11/11:
The Microsoft office 2011 users can Office 2010 work more efficiently with the Microsoft Office 2010 simple and intuitive Download Office 2010 user interface new graphical MS Office 2010 menus and a familiar Office 2010 Key experience provide the Office 2010 Download tools you need to plan and Office 2010 Professional manage your project. And the Microsoft Office 2010 Download tabs and contextual menu buy microsoft office 2010 groupings reveal powerful features, Windows 7 making it easier to get Microsoft Windows 7 started and realize results Win 7. Simply be more productive Download Windows 7 by choosing your own menu Buy Windows 7 options, quick access Office 2007 toolbar settings and Microsoft Office 2007 setting defaults.Enhanced copy Office 2007 Download and paste makes it easy to Office 2007 Professional share information effectively MS Office 2007 with other Office 2007 Key applications while retaining buy microsoft office 2007 formatting. And the added columns Download Office 2007 dynamically by entering Microsoft Office 2007 Professional data without having to first select purchase microsoft office 2007 the data type.
http://softwarestockss.blogspot.com
http://software-stocks.com
32434 wrote on 2/1/12:
Loving the pastels louis vuitton sale for some cause LV clothes normally look greater within the advertisements than even on the runways or red carpet. But for positive this puts me in the mood for some spring time warmth so hurry up and be more than winter louis vuitton speedy mini!I under no circumstances substantially cared for the louis vuitton speedy 25 or this style but I actually really like this bag! I think I was just constantly turned off because these sort of bags look hard to obtain louis vuitton sale into when you are on the go to me?- deciding upon an high priced gift out of thin air may be a daunting process. We are right here to create it just somewhat bit simpler for you with our Holiday louis vuitton speedy 30, and today's installment will concentrate on the safest kind of accessory gift: The Classic Bag.On the other hand, for the fun of it, I just ran this past my husband, who is an lawyer. He opines that Hermes would have grounds to sue simply because one more maker has intentions of turning a profit depending on an louis vuitton speedy'patented style style. In any occasion, I believe these canvas bags are dorky.Appreciate the Louis V and also the retailers have the most beneficial windows of any individual on a continuous basis. Somehow I in no way really like the louis vuitton speedy sale lines, but the LV is superb.What cheap louis vuitton has employed appears to be a lot more of an artistic rendering than a straight-up photo like that applied by louis vuitton luggage Thursday Friday, but apart from that, the idea is exactly the same and I'm betting that Hermes'legal department will react similarlylouis vuitton neverfull and eventually get a comparable settlement.if Hermes is going to invest its income on a court case suing a firm for copying its bags, then speedy louis vuitton should really leave the gently humorous canvas bags alone and go soon after chain retail stores that sell carbon-copy versions of its bags instead.