---
title: "Sending SMS messages with the OVHcloud API in PHP"
description: "Find out how to set up a PHP development environment and send your first SMS message step by step using the OVHcloud RESTful API"
url: https://docs.ovhcloud.com/en/guides/web-cloud/messaging/sms/send-sms-api-php
lang: en
lastUpdated: 2020-06-25
---
# Sending SMS messages with the OVHcloud API in PHP

:::info
OVHcloud SMS offers are only available in the following countries: France, the United Kingdom, Ireland, Spain, Italy and Poland.
:::

## Objective

SMS messages are widely used to share practical information, track an order status or transactional process, send alerts regarding unusual events, and send appointment reminders. This guide details the method for sending a first SMS message via the OVHcloud API in PHP.

**Find out how to send SMS messages with the OVHcloud RESTful API in PHP.**

## Requirements

- a PHP development environment
- an [OVHcloud SMS account](https://www.ovhcloud.com/en-gb/sms/) with SMS credits

## Instructions

### Step 1: Retrieve the PHP wrapper for OVHcloud APIs.

Go to the [https://github.com/ovh/php-ovh](https://github.com/ovh/php-ovh) GitHub project.

You will be able to integrate the PHP wrapper quickly using Composer: [https://getcomposer.org/](https://getcomposer.org/)

Follow the instructions on GitHub, and create the composer.json file as instructed in the project:
GitHub> Readme > Quickstart

In your project, you will retrieve the directory **./vendor/ovh/ovh/
**, as well as the file **autoload.php
**, which is used to manage all dependencies and imports.
![your project with Composer](/images/web-cloud/messaging/sms/send-sms-api-php/img_2450.jpg)
### Step 2: Create your credentials.

You need credentials to use the SMS API. These credentials are created once to identify the application that sends SMS messages. Their lifespan can be configured.

Create all of your script credentials (all keys at once) on this page:
[https://auth.eu.ovhcloud.com/api/createToken](https://auth.eu.ovhcloud.com/api/createToken?GET=/sms/\&GET=/sms/*/jobs\&POST=/sms/*/jobs) (this URL will automatically give you the correct rights for the steps described in this guide).

![create tokens](/images/web-cloud/messaging/sms/send-sms-api-php/img_2451.jpg)
In this basic example, we retrieve the rights to access account information, view pending SMS messages, and send SMS messages.

- GET /sms
- GET /sms/\*/jobs
- POST /sms/\*/jobs

The asterisk (\*) enables calls to these methods for all of your SMS accounts. You can also limit calls to one account by replacing "/sms" with "/sms/ACCOUNT-NAME", and "/sms/\*/" with "/sms/ACCOUNT-NAME".

You can then retrieve the credentials for your script:

- Application Key (identifies your application)
- Application Secret (authenticates your application)
- Consumer Key (authorises the application to access the methods chosen)

![retrieving tokens](/images/web-cloud/messaging/sms/send-sms-api-php/img_2452.jpg)
The environment is ready, the credentials have been created, and you are now ready to code your PHP script.

### Step 3: Set up a PHP SDK (software development kit).

To simplify things, we have set up a PHP SDK, which you can access on the [php-ovh-sms GitHub repository](https://github.com/ovh/php-ovh-sms).

### Step 4: Basic connection to the API.

You can now test the API connection, by displaying the details for each SMS account:

```
<?php
/**
 * Lists and displays the details for each SMS account
 * 
 * Go to https://auth.eu.ovhcloud.com/api/createToken?GET=/sms/&GET=/sms/*/jobs&POST=/sms/*/jobs
 * to generate the API access keys for:
 *
 * GET /sms
 * GET /sms/*/jobs
 * POST /sms/*/jobs
 */

require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;

$endpoint = 'ovh-eu';
$applicationKey = "your_app_key";
$applicationSecret = "your_app_secret";
$consumer_key = "your_consumer_key";

$conn = new Api(    $applicationKey,
                    $applicationSecret,
                    $endpoint,
                    $consumer_key);
     
$smsServices = $conn->get('/sms/');
foreach ($smsServices as $smsService) {

    print_r($smsService);
}

?>
```

When this script launches, you should retrieve the list of your SMS accounts.

### Step 5: Send your first SMS message.

To send SMS messages, use the POST jobs method:


[🇪🇺POST/sms/{serviceName}/jobs](https://eu.api.ovh.com/console/?section=/sms&branch=v1#post-/sms/-serviceName-/jobs)

:::info
**Only for OVHcloud accounts in France excluding DOM-TOM:**

With the senderForResponse setting, you can use a short number, which enables you to send SMS messages directly without needing to create an alpha-numeric sender (e.g. your name).

Short numbers also mean you are able to receive replies from recipients of your SMS messages, which may be useful for satisfaction surveys, voting applications, games, and more.
:::

```
<?php
/**
 * Sends an SMS message, then displays the list of SMS messages that are waiting to be sent.
 * 
 * Go to https://auth.eu.ovhcloud.com/api/createToken?GET=/sms/&GET=/sms/*/jobs&POST=/sms/*/jobs
 * to generate the API access keys for:
 *
 * GET /sms
 * GET /sms/*/jobs
 * POST /sms/*/jobs
 */

require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;

$endpoint = 'ovh-eu';
$applicationKey = "your_app_key";
$applicationSecret = "your_app_secret";
$consumer_key = "your_consumer_key";

$conn = new Api(    $applicationKey,
                    $applicationSecret,
                    $endpoint,
                    $consumer_key);
     
$smsServices = $conn->get('/sms/');
foreach ($smsServices as $smsService) {

    print_r($smsService);
}

$content = (object) array(
	"charset"=> "UTF-8",
	"class"=> "phoneDisplay",
	"coding"=> "7bit",
	"message"=> "Bonjour les SMS OVH par api.ovh.com",
	"noStopClause"=> false,
	"priority"=> "high",
	"receivers"=> [ "+3360000000" ],
	"senderForResponse"=> true,
	"validityPeriod"=> 2880
);
$resultPostJob = $conn->post('/sms/'. $smsServices[0] . '/jobs', $content);

print_r($resultPostJob);

$smsJobs = $conn->get('/sms/'. $smsServices[0] . '/jobs');
print_r($smsJobs);
        
?>
```

This is the kind of response you should expect:

```
sms-XXXXXX-1
Array
(
    [totalCreditsRemoved] => 1
    [invalidReceivers] => Array
        (
        )

    [ids] => Array
        (
            [0] => 26929925
        )

    [validReceivers] => Array
        (
            [0] => +3360000000
        )

)
Array
(
)
```

You will retrieve the SMS account (ServiceName). You will receive a response with 1 credit used per valid number. And you will see that there are no SMS messages waiting to be sent.

#### Commercial SMS size

A commercial SMS message must include the STOP clause. This contains 11 characters and is automatically deducted from the 160 base characters of the first SMS.
The table below therefore indicates the maximum number of characters allowed for commercial SMS messages.

Example: in 7bit encoding, if your message is longer than 149 characters, it will be sent as 2 SMS messages and will therefore cost 2 credits.

| Encoding                  | First SMS      | Second SMS and following |
| ------------------------- | -------------- | ------------------------ |
| 7bit (GSM 03.38 standard) | 149 characters | 153 characters           |
| Unicode                   | 59 characters  | 70 characters            |

## Go further

With the [API console](https://api.ovh.com/console/?section=%2Fsms\&branch=v1), you can explore other methods for using SMS services, such as: SMS messages with the ability to send replies (for OVHcloud accounts in France only), mass-sending a CSV file, advertising mail, acknowledgements of receipt, etc.

Join our [community of users](https://community.ovhcloud.com/).
