{"id":18068,"date":"2026-11-18T23:46:19","date_gmt":"2026-11-18T18:16:19","guid":{"rendered":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/"},"modified":"2026-11-19T00:52:01","modified_gmt":"2026-11-18T19:22:01","slug":"php-sms-api","status":"publish","type":"post","link":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/","title":{"rendered":"Send SMS and OTP in PHP with Fast2SMS API (cURL, no library)"},"content":{"rendered":"<p>This guide shows how to send SMS and OTP from PHP with the Fast2SMS API, using only PHP&#8217;s built-in cURL. You will send a DLT SMS from your own sender ID, send and verify a login OTP with <a href=\"\/help\/smart-otp-setup-guide-fast2sms\/\">Smart OTP<\/a>, read the delivery report and handle errors. At the end there is one small PHP class you can copy into any project, plain PHP or a framework.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Send SMS from your PHP app<\/strong><p>Get your API key, add your DLT template and send your first SMS or OTP from PHP in a few minutes.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Before you start<\/h2>\n<ul>\n<li><strong>PHP 7 or later<\/strong> with the cURL and JSON extensions. Most hosting plans have both switched on.<\/li>\n<li><strong>API key:<\/strong> from <strong>API Key<\/strong> under UTILITY in the panel, with <strong>API Access<\/strong> switched on.<\/li>\n<li><strong>For DLT SMS:<\/strong> an approved entity, sender ID and content template added in <strong>DLT Manager<\/strong>. You need the template&#8217;s <strong>Message ID<\/strong>.<\/li>\n<li><strong>For OTP:<\/strong> a Smart OTP template in <strong>OTP Template List<\/strong>. You need its <strong>OTP ID<\/strong>.<\/li>\n<li><strong>Wallet balance<\/strong> for the messages you send. Every SMS and every OTP send is charged.<\/li>\n<li><strong>Server-side code only.<\/strong> Call the API from your PHP backend. Never print the key into a web page or JavaScript.<\/li>\n<\/ul>\n<h2>Get your API key, Message ID and OTP ID<\/h2>\n<ol class=\"f2s-steps\">\n<li>\n<h3>Copy your API key<\/h3>\n<p>Open <strong>Account Setting<\/strong>, then <strong>API Key<\/strong>. Click <strong>View<\/strong>, enter the OTP sent to your account mobile and copy the <strong>Authorization Key<\/strong>. Keep the <strong>API Access<\/strong> switch on.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-12-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"API Key page with a masked Authorization Key, View and Reset buttons and the API Access switch turned on\"><figcaption>The key goes in the authorization header of every request.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Copy the Message ID of your DLT template<\/h3>\n<p>In the SMS app, open <strong>DLT Manager<\/strong> and then <strong>Content Template<\/strong>. Each approved template card shows a <strong>Message ID<\/strong> and the linked <strong>Sender ID<\/strong>. Copy both. The Message ID is the short number, not the 19-digit Template ID.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/sms-dlt-template-list-hd-14-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"Content Template page in DLT Manager with approved template cards showing Message ID, Sender ID, Template ID and Entity\"><figcaption>Use the Message ID and Sender ID from the same card.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Copy your OTP ID<\/h3>\n<p>Open Smart OTP and then <strong>OTP Template List<\/strong>. Each card has an <strong>OTP ID<\/strong> with a copy icon. If you have no card yet, click <strong>Add OTP Template<\/strong> and link your approved OTP template first.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-9-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"OTP Template List with WhatsApp and SMS OTP template cards, each showing an OTP ID with a copy icon\"><figcaption>One OTP ID per OTP template.<\/figcaption><\/figure>\n<\/li>\n<\/ol>\n<h2>Set up your PHP project<\/h2>\n<p>You do not need Composer or any SMS library. Store the <a href=\"\/help\/api-key-find-reset\/\">API key<\/a> outside your code, for example in an environment variable or a config file that is not in your web root or Git repository.<\/p>\n<pre><code class=\"language-bash\"># .env or server environment\nFAST2SMS_API_KEY=YOUR_API_KEY<\/code><\/pre>\n<p>Read it in PHP with <code>getenv('FAST2SMS_API_KEY')<\/code>. If your host does not support environment variables, use a <code>config.php<\/code> placed one folder above <code>public_html<\/code>.<\/p>\n<p>All the examples below use one small helper that sends a JSON POST and returns the decoded reply with the HTTP code:<\/p>\n<pre><code class=\"language-php\">&lt;?php\nfunction fast2sms_post(string $path, array $data): array\n{\n    $ch = curl_init('https:\/\/www.fast2sms.com' . $path);\n    curl_setopt_array($ch, [\n        CURLOPT_POST           =&gt; true,\n        CURLOPT_RETURNTRANSFER =&gt; true,\n        CURLOPT_CONNECTTIMEOUT =&gt; 5,\n        CURLOPT_TIMEOUT        =&gt; 15,\n        CURLOPT_HTTPHEADER     =&gt; [\n            'authorization: ' . getenv('FAST2SMS_API_KEY'),\n            'Content-Type: application\/json',\n            'Accept: application\/json',\n        ],\n        CURLOPT_POSTFIELDS     =&gt; json_encode($data),\n    ]);\n    $body = curl_exec($ch);\n    $err  = curl_error($ch);\n    $http = curl_getinfo($ch, CURLINFO_HTTP_CODE);\n    curl_close($ch);\n\n    if ($body === false) {\n        return ['ok' =&gt; false, 'http' =&gt; 0, 'error' =&gt; $err, 'data' =&gt; null];\n    }\n    $data = json_decode($body, true);\n    $ok   = $http &gt;= 200 &amp;&amp; $http &lt; 300 &amp;&amp; is_array($data) &amp;&amp; ($data['return'] ?? false) === true;\n    return ['ok' =&gt; $ok, 'http' =&gt; $http, 'error' =&gt; null, 'data' =&gt; $data];\n}<\/code><\/pre>\n<div class=\"f2s-note\">Send the key as it is. Do not add &#8220;Bearer &#8221; in front. The SMS endpoints remove it, but the OTP endpoints do not, and you will get &#8220;Invalid authorization key&#8221;.<\/div>\n<h2>Send a DLT SMS from PHP<\/h2>\n<p>DLT SMS uses <code>\/dev\/bulkV2<\/code> with <code>route=dlt<\/code>. You send the sender ID, the template&#8217;s Message ID, the values for its variables and the numbers. Fast2SMS builds the text from your approved template.<\/p>\n<p>The example template is Message ID 10001 on sender DEMOTR: &#8220;Dear {#var#}, your order {#var#} of Rs.{#var#} is confirmed and will be delivered by {#var#}. &#8211; Demo Traders&#8221;. Use your own values.<\/p>\n<pre><code class=\"language-php\">&lt;?php\n$res = fast2sms_post('\/dev\/bulkV2', [\n    'route'            =&gt; 'dlt',\n    'sender_id'        =&gt; 'DEMOTR',          \/\/ exact case, as in DLT Manager\n    'message'          =&gt; '10001',           \/\/ Message ID, not the 19-digit Template ID\n    'variables_values' =&gt; 'Rahul|DT10458|1240|21 Nov',\n    'numbers'          =&gt; '9999999999',      \/\/ comma-separated for more numbers\n    'udf1'             =&gt; 'order-DT10458',   \/\/ optional, comes back in webhooks\n]);\n\nif ($res['ok']) {\n    $requestId = $res['data']['request_id'];   \/\/ starts with S, save it\n    echo \"Queued. Request ID: $requestId\";\n} else {\n    $code = $res['data']['status_code'] ?? $res['http'];\n    $msg  = $res['data']['message'] ?? $res['error'];\n    echo \"Not sent ($code): \" . (is_array($msg) ? implode(' ', $msg) : $msg);\n}<\/code><\/pre>\n<p>Points to remember:<\/p>\n<ul>\n<li>Variable values go in the same order as the <code>{#var#}<\/code> places, separated by <code>|<\/code>. Each value is cut to 40 characters.<\/li>\n<li>The sender ID is case-sensitive. DEMOTR and demotr are different.<\/li>\n<li>On success, <code>message<\/code> is a list: <code>[\"SMS sent successfully.\"]<\/code>. It means the SMS is accepted and queued, not delivered.<\/li>\n<li>For a later time, add <code>'schedule_time' =&gt; '25-11-2026-10-30'<\/code> (DD-MM-YYYY-HH-MM, IST) or a Unix timestamp.<\/li>\n<\/ul>\n<h2>Send and verify an OTP with Smart OTP<\/h2>\n<p>Smart OTP creates the code, sends it on SMS or WhatsApp from your template and checks it for you. You do not store the OTP in your database. You need three calls: send, verify and (optionally) resend.<\/p>\n<h3>Send the OTP<\/h3>\n<pre><code class=\"language-php\">&lt;?php\n$res = fast2sms_post('\/dev\/otp\/send', [\n    'mobile'     =&gt; '9999999999',\n    'otp_id'     =&gt; 'YOUR_OTP_ID',\n    'otp_expiry' =&gt; 5,   \/\/ minutes, 1 to 10080, default 15\n    'otp_length' =&gt; 6,   \/\/ 4 to 10, default 6\n]);\n\nif ($res['ok']) {\n    echo 'OTP sent';   \/\/ request_id starts with O\n} else {\n    echo $res['data']['message'] ?? 'Could not send OTP';\n}<\/code><\/pre>\n<p>If your template has other variables, such as a name, send them in <code>variables_values<\/code> in order, without the OTP. Fast2SMS fills the OTP variable itself.<\/p>\n<h3>Verify the code the user typed<\/h3>\n<pre><code class=\"language-php\">&lt;?php\n$mobile = preg_replace('\/\\D\/', '', $_POST['mobile'] ?? '');\n$otp    = trim($_POST['otp'] ?? '');\n\n$res = fast2sms_post('\/dev\/otp\/verify', ['mobile' =&gt; $mobile, 'otp' =&gt; $otp]);\n\nif ($res['ok']) {\n    session_regenerate_id(true);\n    $_SESSION['verified_mobile'] = $mobile;   \/\/ log the user in\n    echo 'Verified';\n} else {\n    \/\/ e.g. \"Invalid OTP\", \"OTP expired\", \"OTP not found or already verified\"\n    echo $res['data']['message'] ?? 'Verification failed';\n}<\/code><\/pre>\n<p>Verify needs no OTP ID. It always checks the latest unverified OTP sent to that mobile. If you send a new OTP, every older OTP for that number stops working.<\/p>\n<h3>Resend the same OTP<\/h3>\n<pre><code class=\"language-php\">&lt;?php\n$res = fast2sms_post('\/dev\/otp\/resend', ['mobile' =&gt; '9999999999']);\necho $res['ok'] ? 'Sent again' : ($res['data']['message'] ?? 'Resend failed');<\/code><\/pre>\n<p>Resend sends the <strong>same<\/strong> code again and is charged like a new send. It works for 10 minutes after the first send, and at most 5 sends in that window, counting the first. So a user gets 4 resends. The wait between sends comes from <strong>OTP Settings<\/strong> (default 10 seconds).<\/p>\n<h2>Read the delivery report<\/h2>\n<p>&#8220;SMS sent successfully&#8221; only means Fast2SMS accepted the message. To know if it reached the phone, use one of these two methods. Pick one: calling the DLR API for a request can stop the webhook from sending those same rows.<\/p>\n<h3>Option 1: ask for the status (DLR API)<\/h3>\n<pre><code class=\"language-php\">&lt;?php\n$requestId = 'Sa1B2c3D4e5F6g7';\n$ch = curl_init('https:\/\/www.fast2sms.com\/dev\/dlr\/' . urlencode($requestId));\ncurl_setopt_array($ch, [\n    CURLOPT_RETURNTRANSFER =&gt; true,\n    CURLOPT_TIMEOUT        =&gt; 15,\n    CURLOPT_HTTPHEADER     =&gt; ['authorization: ' . getenv('FAST2SMS_API_KEY')],\n]);\n$data = json_decode(curl_exec($ch), true);\ncurl_close($ch);\n\nforeach ($data['data'][0]['delivery_status'] ?? [] as $row) {\n    echo $row['mobile'] . ': ' . $row['status'] . PHP_EOL;  \/\/ Delivered, Failed or Sent\n}<\/code><\/pre>\n<p>The DLR API looks back 7 days. <code>Sent<\/code> means the operator report has not come yet. Do not call it every second; check a few minutes after sending.<\/p>\n<h3>Option 2: receive a webhook<\/h3>\n<p>Create a webhook in the panel under <strong>Webhook<\/strong>, then <strong>SMS<\/strong> (or <strong>OTP<\/strong>), with your URL, method POST and content type JSON. The <strong>Standard Webhook<\/strong> format sends fields like <code>request_id<\/code>, <code>mobile<\/code>, <code>status<\/code>, <code>status_description<\/code> and <code>udf1<\/code>.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/webhook-create-modal-hd-2-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"CREATE WEBHOOK (SMS) form with Webhook Name, Select Format Standard Webhook, Select Event, Entity ID, Method POST, URL, Content-Type JSON and the JSON body on the right\"><figcaption>Create an SMS webhook with the Standard format and JSON.<\/figcaption><\/figure>\n<p>A simple receiver, saved as <code>fast2sms-webhook.php<\/code>:<\/p>\n<pre><code class=\"language-php\">&lt;?php\n\/\/ Optional: add your own header in the webhook's Headers tab, e.g. X-Webhook-Token\nif (($_SERVER['HTTP_X_WEBHOOK_TOKEN'] ?? '') &#33;== getenv('MY_WEBHOOK_TOKEN')) {\n    http_response_code(401);\n    exit;\n}\n\n$payload = json_decode(file_get_contents('php:\/\/input'), true);\nif (is_array($payload)) {\n    $requestId = $payload['request_id'] ?? '';\n    $mobile    = $payload['mobile'] ?? '';\n    $status    = $payload['status'] ?? '';        \/\/ delivered or failed\n    $reason    = $payload['status_description'] ?? '';\n    \/\/ Save it, e.g. UPDATE messages SET status = ? WHERE request_id = ? AND mobile = ?\n}\n\nhttp_response_code(200);\necho 'OK';<\/code><\/pre>\n<p>Answer with HTTP 200 quickly. Fast2SMS waits up to 10 seconds and tries again up to 3 times, 60 seconds apart, on timeouts and 5xx errors. Every attempt shows in <strong>Webhook Logs<\/strong> for 7 days. Webhooks fire only for messages sent through the API, not for campaigns sent from the panel.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Track every SMS from your PHP app<\/strong><p>Set up a webhook once and get delivered or failed status for every SMS and OTP on your own URL.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Handle errors the right way<\/h2>\n<ul>\n<li><strong>Check <code>return<\/code>, not only the HTTP code.<\/strong> A low wallet balance can come back with HTTP 200 and <code>\"return\": false<\/code> (status_code 416).<\/li>\n<li><strong>Do not retry a send by itself.<\/strong> If a send request times out after reaching Fast2SMS, a retry can send the SMS twice and charge twice. Retry once only when the connection could not be opened at all. Verify calls are free and safe to retry once.<\/li>\n<li><strong>Show friendly text to users<\/strong> and log the real <code>status_code<\/code> and <code>message<\/code> for yourself.<\/li>\n<li><strong>Look at API Logs.<\/strong> Every call with a valid key is in <strong>API Logs<\/strong> for 7 days, with the request, the response and your server IP.<\/li>\n<\/ul>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>Error<\/th>\n<th>Where<\/th>\n<th>Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>412 Invalid Authentication, Check Authorization Key (HTTP 401)<\/td>\n<td>SMS<\/td>\n<td>Wrong, old or empty key. Copy it again from <strong>API Key<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>Invalid authorization key (HTTP 401)<\/td>\n<td>OTP<\/td>\n<td>Wrong key, or &#8220;Bearer &#8221; added in front.<\/td>\n<\/tr>\n<tr>\n<td>413 Authorization Key Disabled<\/td>\n<td>All<\/td>\n<td>Turn <strong>API Access<\/strong> on.<\/td>\n<\/tr>\n<tr>\n<td>414 IP is blacklisted from Dev API section<\/td>\n<td>All<\/td>\n<td><a href=\"\/help\/api-security-ip-whitelist\/\">API Security<\/a> is on. Add your server&#8217;s public IP in <strong>API Security<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>406 Invalid Sender ID<\/td>\n<td>SMS<\/td>\n<td>Use your approved sender in the exact case.<\/td>\n<\/tr>\n<tr>\n<td>424 Invalid Message ID<\/td>\n<td>SMS<\/td>\n<td>Use the Message ID linked to that sender, not the 19-digit Template ID.<\/td>\n<\/tr>\n<tr>\n<td>411 Invalid Numbers<\/td>\n<td>SMS<\/td>\n<td>Every number was invalid. Use 10-digit Indian mobiles starting with 6 to 9.<\/td>\n<\/tr>\n<tr>\n<td>416 You don&#8217;t have sufficient wallet balance<\/td>\n<td>SMS<\/td>\n<td>Recharge the wallet.<\/td>\n<\/tr>\n<tr>\n<td>429 Invalid characters &#8230; not valid UTF-8<\/td>\n<td>SMS<\/td>\n<td>Save your PHP files and data as UTF-8. Nothing was sent or charged.<\/td>\n<\/tr>\n<tr>\n<td>Invalid OTP ID<\/td>\n<td>OTP<\/td>\n<td>Copy the OTP ID again. It must be from the same account as the key.<\/td>\n<\/tr>\n<tr>\n<td>Please wait N seconds before requesting a new OTP<\/td>\n<td>OTP<\/td>\n<td>Show a countdown. The wait is set in <strong>OTP Settings<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>Invalid OTP \/ OTP expired<\/td>\n<td>OTP verify<\/td>\n<td>Let the user retry, or send a new OTP if expired.<\/td>\n<\/tr>\n<tr>\n<td>OTP not found or already verified (HTTP 404)<\/td>\n<td>OTP verify<\/td>\n<td>Already used, replaced by a newer OTP, or never sent. Send a new one.<\/td>\n<\/tr>\n<tr>\n<td>Maximum verification attempts reached<\/td>\n<td>OTP verify<\/td>\n<td>Too many wrong tries. Send a new OTP.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2>Full copy-paste example: a small Fast2SMS class<\/h2>\n<p>Save this as <code>Fast2SMS.php<\/code>. It works in plain PHP, Laravel, CodeIgniter or WordPress code.<\/p>\n<pre><code class=\"language-php\">&lt;?php\nfinal class Fast2SMS\n{\n    private string $key;\n    private string $base = 'https:\/\/www.fast2sms.com';\n\n    public function __construct(?string $key = null)\n    {\n        $this-&gt;key = $key ?? (string) getenv('FAST2SMS_API_KEY');\n    }\n\n    public function sendDlt(string $senderId, string $messageId, array $vars, array $numbers, array $extra = []): array\n    {\n        return $this-&gt;call('POST', '\/dev\/bulkV2', array_merge([\n            'route'            =&gt; 'dlt',\n            'sender_id'        =&gt; $senderId,\n            'message'          =&gt; $messageId,\n            'variables_values' =&gt; implode('|', $vars),\n            'numbers'          =&gt; implode(',', $numbers),\n        ], $extra));\n    }\n\n    public function sendOtp(string $mobile, string $otpId, int $expiryMinutes = 5, array $vars = []): array\n    {\n        $data = ['mobile' =&gt; $mobile, 'otp_id' =&gt; $otpId, 'otp_expiry' =&gt; $expiryMinutes];\n        if ($vars) {\n            $data['variables_values'] = implode('|', $vars);\n        }\n        return $this-&gt;call('POST', '\/dev\/otp\/send', $data);\n    }\n\n    public function verifyOtp(string $mobile, string $otp): array\n    {\n        return $this-&gt;call('POST', '\/dev\/otp\/verify', ['mobile' =&gt; $mobile, 'otp' =&gt; $otp]);\n    }\n\n    public function resendOtp(string $mobile): array\n    {\n        return $this-&gt;call('POST', '\/dev\/otp\/resend', ['mobile' =&gt; $mobile]);\n    }\n\n    public function deliveryReport(string $requestId): array\n    {\n        return $this-&gt;call('GET', '\/dev\/dlr\/' . rawurlencode($requestId));\n    }\n\n    private function call(string $method, string $path, array $data = []): array\n    {\n        $ch = curl_init($this-&gt;base . $path);\n        $opts = [\n            CURLOPT_RETURNTRANSFER =&gt; true,\n            CURLOPT_CONNECTTIMEOUT =&gt; 5,\n            CURLOPT_TIMEOUT        =&gt; 15,\n            CURLOPT_HTTPHEADER     =&gt; [\n                'authorization: ' . $this-&gt;key,\n                'Content-Type: application\/json',\n                'Accept: application\/json',\n            ],\n        ];\n        if ($method === 'POST') {\n            $opts[CURLOPT_POST]       = true;\n            $opts[CURLOPT_POSTFIELDS] = json_encode($data);\n        }\n        curl_setopt_array($ch, $opts);\n        $body = curl_exec($ch);\n        $http = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);\n        $err  = curl_error($ch);\n        curl_close($ch);\n\n        if ($body === false) {\n            return ['ok' =&gt; false, 'http' =&gt; 0, 'status_code' =&gt; null, 'message' =&gt; 'Network error: ' . $err, 'request_id' =&gt; null, 'raw' =&gt; null];\n        }\n        $json = json_decode($body, true);\n        if (&#33;is_array($json)) {\n            return ['ok' =&gt; false, 'http' =&gt; $http, 'status_code' =&gt; null, 'message' =&gt; 'Non-JSON response', 'request_id' =&gt; null, 'raw' =&gt; $body];\n        }\n        $ok  = $http &gt;= 200 &amp;&amp; $http &lt; 300 &amp;&amp; (($json['return'] ?? false) === true || ($json['success'] ?? false) === true);\n        $msg = $json['message'] ?? '';\n        return [\n            'ok'          =&gt; $ok,\n            'http'        =&gt; $http,\n            'status_code' =&gt; $json['status_code'] ?? null,\n            'message'     =&gt; is_array($msg) ? implode(' ', $msg) : (string) $msg,\n            'request_id'  =&gt; $json['request_id'] ?? null,\n            'raw'         =&gt; $json,\n        ];\n    }\n}\n\n\/\/ Usage\n$sms = new Fast2SMS();\n\n$r = $sms-&gt;sendDlt('DEMOTR', '10001', ['Rahul', 'DT10458', '1240', '21 Nov'], ['9999999999']);\necho $r['ok'] ? \"SMS queued: {$r['request_id']}\\n\" : \"SMS error: {$r['message']}\\n\";\n\n$r = $sms-&gt;sendOtp('9999999999', 'YOUR_OTP_ID', 5);\necho $r['ok'] ? \"OTP sent\\n\" : \"OTP error: {$r['message']}\\n\";\n\n$r = $sms-&gt;verifyOtp('9999999999', '482913');\necho $r['ok'] ? \"OTP verified\\n\" : \"Verify error: {$r['message']}\\n\";<\/code><\/pre>\n<p>The DLR API answers with <code>success<\/code> instead of <code>return<\/code>, which is why the class checks both.<\/p>\n<p>If you would rather start from a ready project, Fast2SMS starter kits for plain PHP and Laravel include the same calls with a login page, a mock server and tests.<\/p>\n<h2>Common problems and fixes<\/h2>\n<ul>\n<li><strong>Works on my laptop but not on the server:<\/strong> check that the server&#8217;s outgoing HTTPS is allowed and that, if <strong>API Security<\/strong> is on, the server&#8217;s public IP is whitelisted (<a href=\"\/help\/error-414-ip-blacklisted\/\">error 414<\/a>).<\/li>\n<li><strong>&#8220;SSL certificate problem&#8221; from cURL:<\/strong> your server&#8217;s CA certificates are old. Update the CA bundle. Do not switch off SSL checks.<\/li>\n<li><strong>Hindi text shows as ???:<\/strong> your file, database or form is not UTF-8. Use UTF-8 everywhere (utf8mb4 in MySQL).<\/li>\n<li><strong>OTP verify always says &#8220;OTP not found or already verified&#8221;:<\/strong> your code may be sending a new OTP on page reload, which cancels the earlier one. Send only when the user clicks the button.<\/li>\n<li><strong>Webhook never arrives:<\/strong> the URL must be public HTTPS or HTTP, not localhost. Check <strong>Webhook Logs<\/strong> for the HTTP code your server returned.<\/li>\n<\/ul>\n<section class=\"f2s-faq\">\n<h2>Frequently asked questions<\/h2>\n<h3>Do I need a Composer package to use Fast2SMS in PHP?<\/h3>\n<p>No. The API is plain HTTPS with JSON, so PHP&#8217;s built-in cURL is enough. The class above is all you need.<\/p>\n<h3>Can I use GET instead of POST in PHP?<\/h3>\n<p>Yes, the SMS and OTP endpoints accept GET with query parameters too. POST with JSON keeps the values out of server logs and avoids URL-encoding problems, so it is the better choice.<\/p>\n<h3>How do I send one SMS to many numbers?<\/h3>\n<p>Join the numbers with commas in <code>numbers<\/code>. Invalid numbers are dropped and not charged. You get <a href=\"\/help\/error-411-invalid-numbers\/\">error 411<\/a> only if every number is invalid.<\/p>\n<h3>Can I send an OTP without Smart OTP?<\/h3>\n<p>Yes. Send your own approved DLT OTP template with <code>route=dlt<\/code> and put the code your PHP app made in <code>variables_values<\/code>. Then your app must store and check the code itself. Smart OTP does that work for you.<\/p>\n<h3>Why does the API say sent but the SMS did not arrive?<\/h3>\n<p>&#8220;Sent successfully&#8221; means queued. Check the delivery report for the request ID. Failed DLT SMS are not refunded automatically, so check the reason in <strong>Delivery Report<\/strong>.<\/p>\n<h3>Is the OTP verify call charged?<\/h3>\n<p>No. Send and resend are charged. Verify is not.<\/p>\n<h3>Where do I find the full list of error codes?<\/h3>\n<p>Open <strong>API Documentation<\/strong> from the <strong>API Key<\/strong> page, or see the error codes guide linked below.<\/p>\n<\/section>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Start sending from PHP today<\/strong><p>Sign up, add your DLT template or Smart OTP template and use the class above in your project.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Related guides<\/h2>\n<ul>\n<li><a href=\"\/help\/dlt-sms-api-guide\/\">Fast2SMS DLT SMS API: send SMS with your DLT template<\/a><\/li>\n<li><a href=\"\/help\/smart-otp-send-otp-api\/\">Fast2SMS Send OTP API: parameters and code examples<\/a><\/li>\n<li><a href=\"\/help\/smart-otp-verify-otp-api\/\">Fast2SMS Verify OTP API: how verification works<\/a><\/li>\n<li><a href=\"\/help\/fast2sms-webhooks-setup-delivery-reports\/\">Webhooks in Fast2SMS: get delivery reports on your own URL<\/a><\/li>\n<li><a href=\"\/help\/fast2sms-api-error-codes\/\">Fast2SMS API error codes and fixes<\/a><\/li>\n<li><a href=\"https:\/\/www.fast2sms.com\/otp-sms\">Fast2SMS OTP SMS<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This guide shows how to send SMS and OTP from PHP with the Fast2SMS API, using only PHP&#8217;s built-in cURL. You will send a DLT SMS from your own sender ID, send and verify a login OTP with Smart OTP, read the delivery report and handle errors. At the end there is one small PHP [&hellip;]<\/p>\n","protected":false},"featured_media":18063,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,13,5],"tags":[],"class_list":["post-18068","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-api","category-bulk-sms","category-otp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Send SMS and OTP in PHP: SMS API Code | Fast2SMS<\/title>\n<meta name=\"description\" content=\"Send DLT SMS and OTP from PHP with the Fast2SMS API using cURL. Smart OTP send and verify, delivery report, webhook receiver, error handling and a class.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.fast2sms.com\/help\/php-sms-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Send SMS and OTP in PHP: SMS API Code | Fast2SMS\" \/>\n<meta property=\"og:description\" content=\"Send DLT SMS and OTP from PHP with the Fast2SMS API using cURL. Smart OTP send and verify, delivery report, webhook receiver, error handling and a class.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.fast2sms.com\/help\/php-sms-api\/\" \/>\n<meta property=\"og:site_name\" content=\"Fast2SMS\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Fast2SMS\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-18T18:16:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-18T19:22:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-12-scaled.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fast2sms\" \/>\n<meta name=\"twitter:site\" content=\"@fast2sms\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/php-sms-api\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/php-sms-api\\\/\"},\"author\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"headline\":\"Send SMS and OTP in PHP with Fast2SMS API (cURL, no library)\",\"datePublished\":\"2026-11-18T18:16:19+00:00\",\"dateModified\":\"2026-11-18T19:22:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/php-sms-api\\\/\"},\"wordCount\":1822,\"publisher\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/php-sms-api\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/api-key-hd-12-scaled.webp\",\"articleSection\":[\"API\",\"Bulk SMS\",\"OTP\"],\"inLanguage\":\"en-IN\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/php-sms-api\\\/\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/php-sms-api\\\/\",\"name\":\"Send SMS and OTP in PHP: SMS API Code | Fast2SMS\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/php-sms-api\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/php-sms-api\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/api-key-hd-12-scaled.webp\",\"datePublished\":\"2026-11-18T18:16:19+00:00\",\"dateModified\":\"2026-11-18T19:22:01+00:00\",\"description\":\"Send DLT SMS and OTP from PHP with the Fast2SMS API using cURL. Smart OTP send and verify, delivery report, webhook receiver, error handling and a class.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/php-sms-api\\\/#breadcrumb\"},\"inLanguage\":\"en-IN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/php-sms-api\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-IN\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/php-sms-api\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/api-key-hd-12-scaled.webp\",\"contentUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/api-key-hd-12-scaled.webp\",\"width\":2560,\"height\":1600,\"caption\":\"API Key page with a masked Authorization Key, View and Reset buttons and the API Access switch turned on\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/php-sms-api\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"API\",\"item\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/api\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Send SMS and OTP in PHP with Fast2SMS API (cURL, no library)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/#website\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/\",\"name\":\"Fast2SMS\",\"description\":\"Help\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"inLanguage\":\"en-IN\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\",\"name\":\"Fast2SMS\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#logo\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/Fast2SMS.png\",\"contentUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/Fast2SMS.png\",\"caption\":\"Fast2SMS\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#logo\"},\"email\":\"support@fast2sms.com\",\"telephone\":\"+91-6262778822\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Fast2SMS\",\"https:\\\/\\\/www.instagram.com\\\/fast2sms\",\"https:\\\/\\\/x.com\\\/fast2sms\",\"https:\\\/\\\/www.youtube.com\\\/Fast2SMSofficial\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/fast2sms\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Send SMS and OTP in PHP: SMS API Code | Fast2SMS","description":"Send DLT SMS and OTP from PHP with the Fast2SMS API using cURL. Smart OTP send and verify, delivery report, webhook receiver, error handling and a class.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/","og_locale":"en_US","og_type":"article","og_title":"Send SMS and OTP in PHP: SMS API Code | Fast2SMS","og_description":"Send DLT SMS and OTP from PHP with the Fast2SMS API using cURL. Smart OTP send and verify, delivery report, webhook receiver, error handling and a class.","og_url":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/","og_site_name":"Fast2SMS","article_publisher":"https:\/\/www.facebook.com\/Fast2SMS\/","article_published_time":"2026-11-18T18:16:19+00:00","article_modified_time":"2026-11-18T19:22:01+00:00","og_image":[{"width":2560,"height":1600,"url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-12-scaled.webp","type":"image\/webp"}],"twitter_card":"summary_large_image","twitter_creator":"@fast2sms","twitter_site":"@fast2sms","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/#article","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/"},"author":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"headline":"Send SMS and OTP in PHP with Fast2SMS API (cURL, no library)","datePublished":"2026-11-18T18:16:19+00:00","dateModified":"2026-11-18T19:22:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/"},"wordCount":1822,"publisher":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-12-scaled.webp","articleSection":["API","Bulk SMS","OTP"],"inLanguage":"en-IN"},{"@type":"WebPage","@id":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/","url":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/","name":"Send SMS and OTP in PHP: SMS API Code | Fast2SMS","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/#primaryimage"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-12-scaled.webp","datePublished":"2026-11-18T18:16:19+00:00","dateModified":"2026-11-18T19:22:01+00:00","description":"Send DLT SMS and OTP from PHP with the Fast2SMS API using cURL. Smart OTP send and verify, delivery report, webhook receiver, error handling and a class.","breadcrumb":{"@id":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/#breadcrumb"},"inLanguage":"en-IN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.fast2sms.com\/help\/php-sms-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-IN","@id":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/#primaryimage","url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-12-scaled.webp","contentUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-12-scaled.webp","width":2560,"height":1600,"caption":"API Key page with a masked Authorization Key, View and Reset buttons and the API Access switch turned on"},{"@type":"BreadcrumbList","@id":"https:\/\/www.fast2sms.com\/help\/php-sms-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.fast2sms.com\/help\/"},{"@type":"ListItem","position":2,"name":"API","item":"https:\/\/www.fast2sms.com\/help\/api\/"},{"@type":"ListItem","position":3,"name":"Send SMS and OTP in PHP with Fast2SMS API (cURL, no library)"}]},{"@type":"WebSite","@id":"https:\/\/www.fast2sms.com\/help\/#website","url":"https:\/\/www.fast2sms.com\/help\/","name":"Fast2SMS","description":"Help","publisher":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"inLanguage":"en-IN"},{"@type":"Organization","@id":"https:\/\/www.fast2sms.com\/#organization","name":"Fast2SMS","url":"https:\/\/www.fast2sms.com\/","logo":{"@type":"ImageObject","@id":"https:\/\/www.fast2sms.com\/#logo","url":"https:\/\/www.fast2sms.com\/Fast2SMS.png","contentUrl":"https:\/\/www.fast2sms.com\/Fast2SMS.png","caption":"Fast2SMS"},"image":{"@id":"https:\/\/www.fast2sms.com\/#logo"},"email":"support@fast2sms.com","telephone":"+91-6262778822","sameAs":["https:\/\/www.facebook.com\/Fast2SMS","https:\/\/www.instagram.com\/fast2sms","https:\/\/x.com\/fast2sms","https:\/\/www.youtube.com\/Fast2SMSofficial","https:\/\/www.linkedin.com\/company\/fast2sms"]}]}},"_links":{"self":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/18068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/comments?post=18068"}],"version-history":[{"count":1,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/18068\/revisions"}],"predecessor-version":[{"id":19385,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/18068\/revisions\/19385"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media\/18063"}],"wp:attachment":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media?parent=18068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/categories?post=18068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/tags?post=18068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}