
PHP
Send SMS in PHP
Install taysend/sdk with Composer, or call the API with cURL. Both use a Bearer API key.
Package
composer require taysend/sdk
composer
composer require taysend/sdksend-sdk.php
<?php
require "vendor/autoload.php";
use Taysend\Client;
$sms = new Client(getenv("TAYSEND_KEY"));
$message = $sms->send([
"to" => "+233200000001",
"sender_id" => "TAYSEND",
"message" => "Hello from Taysend",
"type" => "transactional",
]);
echo $message["id"];HTTP
Send SMS with cURL
send.php
<?php
$base = getenv('API_URL') ?: 'https://api.taysend.com';
$key = getenv('TAYSEND_KEY');
$ch = curl_init($base . '/v1/messages');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $key,
'Idempotency-Key: ' . uniqid('', true),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '+233200000001',
'sender_id' => 'TAYSEND',
'message' => 'Hello from Taysend',
'type' => 'transactional',
]),
]);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($response, true);
echo $code, ' ', $data['id'] ?? '', PHP_EOL;OTP
OTP verification
otp.php
<?php
$ch = curl_init($base . '/v1/verify/send');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $key,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '+233200000001',
'locale' => 'en',
]),
]);
echo curl_exec($ch);Validate with POST /v1/verify/check. Details at /developers/otp.
Tips
Production tips
- Store TAYSEND_KEY in .env — never commit sms_live_ keys.
- Use uniqid or UUID for Idempotency-Key on every send.
- LIVE sends need an approved sender_id (3–11 alphanumeric chars).
- TEST keys use +233200000001–006 simulated outcomes.
Explore
Related
Each page answers a different question. They are not copies of this one.