How to send SMS messages
With the Silverstreet API it is really simple the send SMS, including Unicode and long SMS, to one or more mobile phone numbers. In this tutorial we will explain how to do it.
To send an SMS you need to know at least 3 things:
- The recipient, so the number of the person you want the SMS to.
- The body, so the message you want to send.
- The sender, so what the recipients sees who sent the SMS.
The recipient of the SMS the mobile number you will send the SMS to. The recipient must always be in international format, without leading `+` or `00`. In international format means that you have add the country prefix to the local number. For example, if the country prefix is `+31` and the local number is `0612345678`, you remove the leading `0` of the local number and prepend the country prefix. As you then have to strip the leading `+` or `00`, the result will be `31612345678`.
The body of the SMS is the actual text you want to send. When sending an SMS you have to consider the maximum length of the SMS. The maximum length depends on the character set you use. For 7-bit GSM characters the maximum length is 160 characters and for Unicode the maximum length is 70 characters. Sometimes you want to send longer SMS to your customers. In the tutorial ‘How to send a concatenated/long SMS‘ we will explain how you can do that.
The 7-bit GSM character set is a limited set of characters you can send. The following characters are available in this character set:
When you want to send other characters, e.g. Chinese, you have to use Unicode. Our API will simply detect if the body is 7-bit GSM or not, so you don’t have to do anything for that.
The sender of an SMS is where the SMS comes from. So when you send an SMS with your mobile phone, the receiver will see your number. With our API you can set your own sender but also an alphanumeric sender, for example your company name. In our tutorial ‘What is the sender ID of an SMS‘ we will explain more about the sender.
Besides the recipient, body and sender, there are other settings you can do for an SMS. Checkout our API specification for more information on those settings.
Example sending an SMS
So how can you send an SMS with our API? Here an example:
$body = 'This is the body of the SMS.';
$recipient = '316987654321';
$sender = '316123456789';$sms = $client->createSms($body, $recipient, $sender);
When you have submitted the SMS, you can get the status of the SMS. To get the status of an SMS, there a few options. You can simply get the status of the SMS by the id when submitting the SMS, poll for delivery reports or receive a HTTP call from our system. More information on that you can find in our API documentation. For this tutorial we will simply get the status based on the id.
$result = $client->getSms($sms->getMessageId());
Example of the data returned by the API:
"body": "Body of the SMS",
"sender": "Hello world",