PHP Wrapper
Send SMS using our PHP wrapper. We’ve done all the hard work creating the XML and making the HTTP request, you just need to write a few lines of code. Download the PHP wrapper or include it using Composer by adding Clockwork to your composer.json file.
1
2
3
4
5
{
"require": {
"mediaburst/clockworksms": "2.0.*"
}
}
Alternatively you can include the files directly. If you are using your own autoloader we are using the PSR-4 namespacing scheme.
1
2
3
4
<?php
require 'src/Clockwork.php';
require 'src/ClockworkException.php';
?>
You can then use Clockwork like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
try
{
// Create a Clockwork object using your API key
$clockwork = new mediaburst\ClockworkSMS\Clockwork( $API_KEY );
// Setup and send a message
$message = array( 'to' => '447000000000', 'message' => 'Hello World' );
$result = $clockwork->send( $message );
// Check if the send was successful
if($result['success']) {
echo 'Message sent - ID: ' . $result['id'];
} else {
echo 'Message failed - Error: ' . $result['error_message'];
}
}
catch (mediaburst\ClockworkSMS\ClockworkException $e)
{
echo 'Exception sending SMS: ' . $e->getMessage();
}
?>
Full documentation can be found in the Readme file. If you have any questions get in touch.