OVHcloud SMS API
Learn how to use the OVHcloud SMS API with PHP to send SMS messages.
IMPORTANT: This tutorial explains how to use the OVHcloud SMS API to send SMS messages in France. It uses services and features available in France that may not be available in other countries. OVHcloud SMS offers are currently (2026) available in France, the United Kingdom, Ireland, Spain, Italy, and Poland. Available services, pricing, API configuration, and sender settings may vary depending on the country associated with your OVHcloud account.
To edit a SMS on-line while computing the size of the message and the number of SMS sent, see the page Editing a SMS.
98 / 160 - 1 SMS 7bit
OVHcloud account → SMS account → API credentials → ovh.inc → sending an SMS in PHP
Create an account with OVHcloud.
Go to the OVHcloud SMS Pro page. Create an SMS account. NOTE: New customers in France can benefit from 20 free SMS credits to test the service.
From the dashboard of your OVHcloud customer account, click Telecom and then SMS.
The SMS account name is displayed, e.g. sms-ce10000-1.
Sending SMS messages with the OVHcloud API in PHP
Install the OVHcloud API code at the root of the site with Composer:
$ cd /var/www/izendsms.com
$ composer require ovh/ovh
The command created the folder vendor and the files composer.json and composer.lock.
"require": {
"ovh/ovh": "^3.5"
}
}
Edit the file .gitignore at the root of the site. Add composer.lock at the end of the file. NOTE: The folder vendor is already in the list of the files ignored by Git. If not, add it.
Git
- /izendsms.com
- .gitignore
- composer.json
Commit this version
$ git status
$ git add composer.json .gitignore
$ git commit -m'Requires ovh/ovh in composer.json'
Using the API requires 5 parameters:
$ovh_endpoint |
API region: ovh-eu |
$ovh_application_key |
Identifies the application |
$ovh_application_secret |
Authenticates the application |
$ovh_consumer_key |
Authorizes the application to access the API |
$ovh_service_name |
Name of the SMS account associated with the OVHcloud account |
The parameters $ovh_application_key, $ovh_application_secret and $ovh_consumer_key are provided when creating the API credentials.
The parameter $ovh_endpoint is set to ovh-eu for the OVHcloud API in Europe.
The parameter $ovh_service_name identifies the SMS account associated with the OVHcloud account for which the API credentials were created.
Create the file ovh.inc in the folder includes with the following content:
- global $ovh_endpoint;
- $ovh_endpoint='ovh-eu';
- global $ovh_application_key, $ovh_application_secret, $ovh_consummer_key;
- $ovh_application_key=false;
- $ovh_application_secret=false;
- $ovh_consumer_key=false;
- global $ovh_service_name;
- $ovh_service_name=false;
Go to the page Create API Keys to create the credentials associated to the OVhcloud account with an active SMS account.
Authorize the following requests:
| GET | /sms/ | GET | /sms/*/jobs |
| POST | /sms/*/jobs |
| GET | /sms/* |
| DELETE | /sms/*/jobs/* |
Press Create.
Assign the application key (AK) to the parameter $ovh_application_key, the application secret key (AS) to the parameter $ovh_application_secret and the authorization token (CK) to the parameter $ovh_consummer_key.
Assign the name of the SMS account to the parameter $ovh_service_name.
Create the file tests/testovhsms.php with the following content:
- define('ROOT_DIR', dirname(__FILE__));
- set_include_path(get_include_path() . PATH_SEPARATOR . ROOT_DIR . DIRECTORY_SEPARATOR . 'library');
- set_include_path(get_include_path() . PATH_SEPARATOR . ROOT_DIR . DIRECTORY_SEPARATOR . 'includes');
- define('USAGE', 'php -f %s name | info | send telnum msgtext | pending | cancel smsid');
- function abort($msg, $code=1) {
- echo $msg, PHP_EOL;
- exit($code);
- }
- function usage() {
- global $argv;
- abort(sprintf(USAGE, basename($argv[0])), 1);
- }
- require_once 'ovh.inc';
- if (! ($ovh_application_key and $ovh_application_secret and $ovh_consumer_key)) {
- abort('ovh.inc?');
- }
- require_once 'vendor/autoload.php';
- use \Ovh\Api;
- $ovh = new Api($ovh_application_key, $ovh_application_secret, $ovh_endpoint, $ovh_consumer_key);
- if (!($argc >= 2)) {
- usage();
- }
- $telnum=$msgtext=$smsid=false;
- $action=$argv[1];
- switch ($action) {
- case 'name';
- break;
- case 'info';
- break;
- case 'send';
- if (!($argc == 4)) {
- usage();
- }
- $telnum=$argv[2];
- $msgtext=$argv[3];
- break;
- case 'pending';
- break;
- case 'cancel';
- if (!($argc == 3)) {
- usage();
- }
- $smsid=$argv[2];
- break;
- default:
- usage();
- }
- switch ($action) {
- case 'name';
- try {
- $r = $ovh->get('/sms/');
- print_r($r);
- }
- catch (Exception $e) {
- die($e->getMessage());
- }
- break;
- case 'info';
- try {
- $r = $ovh->get('/sms/' . $ovh_service_name);
- print_r($r);
- }
- catch (Exception $e) {
- die($e->getMessage());
- }
- break;
- case 'send';
- $args = array(
- 'senderForResponse' => true,
- 'message' => $msgtext,
- 'receivers' => array($telnum),
- 'validityPeriod' => '1440',
- 'differedPeriod' => '2880',
- );
- try {
- $r = $ovh->post('/sms/' . $ovh_service_name . '/jobs', $args);
- print_r($r);
- }
- catch (Exception $e) {
- die($e->getMessage());
- }
- break;
- case 'pending';
- try {
- $r = $ovh->get('/sms/' . $ovh_service_name . '/jobs');
- print_r($r);
- }
- catch (Exception $e) {
- die($e->getMessage());
- }
- break;
- case 'cancel';
- try {
- $r = $ovh->delete('/sms/' . $ovh_service_name . '/jobs/' . $smsid);
- }
- catch (Exception $e) {
- die($e->getMessage());
- }
- break;
- default:
- break;
- }
Create a link to the file tests/testovhsms.php in the root folder of the site:
$ ln tests/testovhsms.php testovhsms.php
In the root folder of the site, try the script:
$ php -f testovhsms.php
php -f testovhsms.php name | info | send telnum msgtext | pending | cancel smsid
The program displays its usage.
Verify the name of the SMS account
$ php -f testovhsms.php name
Array
(
[0] => sms-ce10000-1
)
Verify that the $ovh_service_name configuration parameter defined in the ovh.inc file refers to an SMS account returned in the list.
IMPORTANT: The other commands of the script testovhsms.php use the parameter $ovh_service_name.
Display the options of the service:
$ php -f testovhsms.php info
Array
(
...
[status] => enable
[creditsLeft] => 20
[name] => sms-ce10000-1
...
)
In the case of an access error, the program displays an HTTP 403 error:
Client error: `GET https://eu.api.ovh.com/1.0/sms/sms-ce10000-1/` resulted in a `403 Forbidden` response {"class":"Client::Forbidden","message":"This call has not been granted","httpCode":"403 Forbidden","errorCode":"NOT_GRAN (truncated...)
The credentials do not give access to a GET '/sms/*' request.
Recreate the credentials with all the necessary access rights.
Send a SMS using the telephone number associated to the SMS account:
$ php -f testovhsms.php send +3360000000 'iZend - The web engine - http://www.izend.org'
Array
(
[tag] => rzz3lb0jg98ekk2a
[validReceivers] => Array
(
[0] => +33600000000
)
[creditsLeft] => 19
[invalidReceivers] => Array
(
)
[totalCreditsRemoved] => 1
[ids] => Array
(
[0] => 12345678
)
)
Note the number returned by the field [ids], e.g. 12345678..
IMPORTANT: The script testovhsms.php doesn't request that the SMS is sent immediately but programs a delay of 24 hours. By deleting the request in time, you can test the API without consuming your credit. If you wish to check the reception of the SMS, comment out the parameter validityPeriod in the code.
Check in your client space at OVHcloud that sending the SMS is scheduled.
Display the delayed tasks:
$ php -f testovhsms.php pending
Array
(
[0] => 12345678
)
Cancel sending the SMS:
$ php -f testovhsms.php cancel 12345678
Check in your client space at OVHcloud that you have recovered your SMS credit.
Git
Delete the link on the file tests/testovhsms.php in the root folder of the site:
$ rm testovhsms.php
- /izendsms.com
- includes
- ovh.inc
- tests
- testovhsms.php
- includes
Commit this version:
$ git status
$ git add includes/ovh.inc tests/testovhsms.php
$ git commit -m'Adds the SMS API by OVHcloud'

Comments