SMS Quickstart

The fastest way to get started with ClickSend API in your preferred coding language.

On this page, you will...

  1. Sign up for a ClickSend account and get your API credentials.
  2. Set up your development environment to work with our API.
  3. Send your first SMS.

Before you start

  1. You need a ClickSend account with credit to start sending. If you don’t have an account, create one here.
  2. If you need to add more credit to your account, you can top up here. You’ll be credited $2 AUD free credit when you sign up.

Installation

To install the bindings via Composer, run the following command in terminal, inside your project directory:

            
                composer require clicksend/clicksend-php
            
        

Send your first message

Below is the full snippet you can use to send an SMS. It includes placeholders that will need to be replaced when implementing the code in your project.

Placeholder

Replace with

USERNAME

Your ClickSend Username. Find it here.

API_KEY

Your ClickSend API key. Find it here.

SOURCE

The origin identifier for your API request, which could be the name of your application or the source location for the request.

MESSAGE

The content of your SMS message.

TO_PHONE_NUMBER

The phone number you're sending the message to, including the country code.

            
                <?php
require_once(__DIR__ . '/vendor/autoload.php');

$config = ClickSend\Configuration::getDefaultConfiguration()
    ->setUsername('USERNAME')
    ->setPassword('API_KEY');

$apiInstance = new ClickSend\Api\SMSApi(new GuzzleHttp\Client(),$config);

$msg = new \ClickSend\Model\SmsMessage();
$msg->setSource("SOURCE");
$msg->setBody("MESSAGE"); 
$msg->setTo("TO_PHONE_NUMBER");

$sms_messages = new \ClickSend\Model\SmsMessageCollection(); 
$sms_messages->setMessages([$msg]);

try {
    $result = $apiInstance->smsSendPost($sms_messages);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling SMSApi->smsSendPost: ', $e->getMessage(), PHP_EOL;
}
?>
            
        

The code explained

Include files

Start by preparing your environment to use the ClickSend API by including the required autoload file. This will automatically load the classes you need without you having to explicitly include them.

            
                require_once(__DIR__ . '/vendor/autoload.php');
            
        

Authorisation

Next, add your API credentials so you can use the ClickSend API in your project.

In the following snippet, simply replace the USERNAME and API_KEY placeholders with your own Username and API key. These can be found in your Dashboard here.

            
                $config = ClickSend\Configuration::getDefaultConfiguration()
    ->setUsername('USERNAME')
    ->setPassword('API_KEY');
            
        

Create an instance of the API class

The following snippet of code will create an instance of the SMSApi class, which is configured to work with the credentials that we set up in the previous step. This instance will be called in the following steps, allowing you to interact with ClickSend’s SMS functionality.

            
                $apiInstance = new ClickSend\Api\SMSApi(new GuzzleHttp\Client(),$config);
            
        

Configure your message

It’s time to configure the content of your message and specify who you’re sending to. This code includes everything you need to send an SMS message. To see what other parameters you can include, see our full API reference.

Now, it’s a simple matter of a few tweaks:

  1. Replace SOURCE with your preferred source (eg. the name of your application). This is not seen by recipients, but will help you to identify messages sent from various applications.
  2. Replace MESSAGE with your own message.
  3. Replace TO_PHONE_NUMBER with your own mobile number, including country code. For example, if you have an Australian number, it will start with +61.
            
                $msg = new \ClickSend\Model\SmsMessage();
$msg->setSource("SOURCE");
$msg->setBody("MESSAGE"); 
$msg->setTo("TO_PHONE_NUMBER");
            
        

Create an SMS message collection

Next, we’ll create a collection and add the SmsMessage that you created earlier.

            
                $sms_messages = new \ClickSend\Model\SmsMessageCollection(); 
$sms_messages->setMessages([$msg]);
            
        

Send SMS message

Finally, try to call the smsSendPost method using the apiInstance you created earlier. If everything works as expected then it will print the formatted response.

If an exception occurs during the API call, it catches the Exception and prints an error message with the exception details. This structure helps you handle both successful API calls and potential errors that might occur during the process.

            
                try {
    $result = $apiInstance->smsSendPost($sms_messages);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling SMSApi->smsSendPost: ', $e->getMessage(), PHP_EOL;
}
?>
            
        

Two people at a race starting line graphic

Start sprinting with our API docs

Get all the detail you'll ever need in our full API docs. Learn how to launch your own features or integrate with others.