Receive SMS verification codes with PHP
Quick answer
PHP's cURL extension is enough to use the Noir SMS API. Send a POST to /api/v1/numbers with your Bearer key and a JSON body with service and country, then poll GET /api/v1/numbers/{id} until status is received. The SMS code is in sms[0].code. Unused numbers are refunded automatically, and you can cancel after 2 minutes.
Many SMS panels and reseller sites run on PHP. This helper shows the full flow with cURL and no framework.
The helper
<?php
$api = 'https://noirsms.com/api/v1';
$key = getenv('NOIRSMS_KEY');
function noir($method, $path, $body = null) {
global $api, $key;
$ch = curl_init($api . $path);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer $key", 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => $body ? json_encode($body) : null,
]);
$res = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status >= 400) throw new Exception($res['error']['code'] ?? 'http_' . $status);
return $res;
}
$n = noir('POST', '/numbers', ['service' => 'go', 'country' => 'ca']);
echo "Number: {$n['phone']}\n";
for ($i = 0; $i < 300; $i++) {
$s = noir('GET', '/numbers/' . $n['id']);
if ($s['status'] === 'received') { echo "Code: {$s['sms'][0]['code']}\n"; break; }
if (in_array($s['status'], ['canceled', 'expired'])) break;
sleep(4);
}Inside a web panel
- Don't hold a web request open for minutes. Create the order, return, and let a cron job or webhook update the code.
- Store the number id, status and code in your database.
- Show customers your own price; your cost comes from GET /services.
Use it responsibly
Use the API only for your own legitimate accounts or apps you're authorized to test, and make sure your customers follow the same Acceptable Use Policy.
Frequently asked questions
Which PHP version do I need?
Any supported PHP version with the cURL and JSON extensions.
Can I use Guzzle?
Yes. The API is standard REST, so any HTTP client works.
Services in this guide
Keep reading
Building an SMS verification panel on the Noir SMS API
How to build your own SMS verification panel or reseller site on the Noir SMS API: architecture, database, webhooks, pricing and abuse rules.
Read the guide →DevelopersReceive SMS verification codes with Python
Buy a temporary number and read the SMS verification code from Python with the Noir SMS REST API. Full example with requests, polling and errors.
Read the guide →DevelopersCommon Noir SMS API errors and how to handle them
Every Noir SMS API error code explained: invalid_api_key, insufficient_balance, no_numbers, too_early, rate_limited and more, with a retry pattern.
Read the guide →DevelopersUsing virtual numbers to test SMS flows
How QA teams use real virtual numbers to test SMS sign-up and OTP flows end to end, when to use them vs test numbers, and how to automate with an API.
Read the guide →DevelopersReceive SMS verification codes with Node.js
Buy a temporary number and read SMS verification codes from Node.js with fetch and the Noir SMS REST API. Complete example with error handling.
Read the guide →DevelopersTesting OTP and SMS sign-up flows in staging
Run end-to-end tests of your app's SMS sign-up in staging with real temporary numbers: Playwright example, what to check and how to keep costs low.
Read the guide →