This is a bit of a work in progress while the documentation is still not finished, I'm basically putting some examples of how to use SMS_Clickatell.
Querying your balance (of available SMS Credits) which you have with Clickatell:
<?php
require_once 'SMS/Clickatell.php';
$sms = new SMS_Clickatell;
$res = $sms->init (
array (
'user' => 'username',
'pass' => 'password',
'api_id' => '12345'
)
);
$res = $sms->auth();
echo 'Credits remaining: ' . $sms->getbalance() . '\n';
?>
Initially when the SMS_Clickatell code was being written I had a company called Ataris Technologies which used SMS messaging for various projects. The "sample code" provide by Clickatell does not provide an easy way for integrating into their gateway without modifying the provided code and adding error checking, etc. etc.
Using the curl extension (in PHP) one can securely connect using HTTPS to Clickatell's API server. The PEAR component enables easier integration into Clickatell's API server as the bulk of the code has been written (the interfacing with Clickatell's API Server), one has more control of how your application interfaces with SMS_Clickatell.
Errors are returned as PEAR_Errors. Which makes it easier for you to display error messages in your application rather than having error messages displayed randomly on the screen.
An example of code for sending a SMS message to a single recipient:
<?php
require_once 'SMS/Clickatell.php';
$sms = new SMS_Clickatell;
$res = $sms->init (
array (
'user' => 'username',
'pass' => 'password',
'api_id' => '12345'
)
);
$res = $sms->auth();
if (PEAR::isError($res)) {
die ($res->getMessage());
}
$sent = $sms->sendmsg (
array(
'from' => 'YourName',
'to' => $_POST['recipient'],
'text' => stripslashes($_POST['msg']),
'msg_type' => $_POST['msg_type'],
'climsgid' => $climsgid
)
);
if (PEAR::isError($sent)) {
die ($sent->getMessage());
}
echo 'Your message ID to the gateway is ' . trim($sent['1']) . '\n';
?>

Continue reading "SMS_Clickatell :: tutorial" »