<?php
header('Content-Type: application/json; charset=utf-8');

function send_single_sms($mobile_no, $message)
{
    $url = 'https://www.24bulksmsbd.com/api/smsSendApi';

    $data = [
        'customer_id' => 547,
        'api_key' => '178412941362886001736699933',
        'message' => $message,
        'mobile_no' => $mobile_no
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

    $response = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch);

    if ($response === false) {
        return [
            'status' => 'error',
            'message' => $error
        ];
    }

    return [
        'status' => 'success',
        'message' => 'SMS sent',
        'response' => $response
    ];
}

$number  = trim($_GET['number'] ?? '');
$message = trim($_GET['message'] ?? '');

if ($number === '' || $message === '') {
    echo json_encode([
        'status' => 'error',
        'message' => 'number and message required'
    ]);
    exit;
}

// FORCE SINGLE SMS ONLY
if (strpos($number, ',') !== false) {
    echo json_encode([
        'status' => 'error',
        'message' => 'Only single number allowed'
    ]);
    exit;
}

echo json_encode(send_single_sms($number, $message));