eSMSAfrique
Tarifs Connexion Démarrer
PHP

How to send SMS from PHP

Send an SMS from PHP using cURL and the eSMS Africa SMS API.

php
<?php
$ch = curl_init("https://api.esmsafrica.io/v1/sms/send");
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer " . getenv("ESMS_API_KEY"),
    "Content-Type: application/json",
  ],
  CURLOPT_POSTFIELDS => json_encode([
    "to" => "+254712345678",
    "from" => "MyBrand",
    "message" => "Hello from PHP",
  ]),
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $status . " " . $response;

Send an SMS with cURL

Read your API key from the environment and POST a JSON body.

php
<?php
$ch = curl_init("https://api.esmsafrica.io/v1/sms/send");
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer " . getenv("ESMS_API_KEY"),
    "Content-Type: application/json",
  ],
  CURLOPT_POSTFIELDS => json_encode([
    "to" => "+254712345678",
    "from" => "MyBrand",
    "message" => "Hello from PHP",
  ]),
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $status . " " . $response;

FAQ

Can I use Guzzle instead of cURL?

Yes. Any HTTP client works - the endpoint is a standard JSON POST. An official PHP SDK is also available.

Ready to send?
Get an API key free and reach every African network.