
PHP
Send SMS in PHP with cURL
Integrate Taysend from plain PHP or any framework using cURL. Authenticate with Bearer keys, send JSON to POST /v1/messages, and poll GET /v1/messages/:id for delivery status.
Send
Send SMS
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.
Next