PHP code example of pratiksahu2003 / smscountry-php-sdk
1. Go to this page and download the library: Download pratiksahu2003/smscountry-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pratiksahu2003 / smscountry-php-sdk example snippets
declare(strict_types=1);
ountry\Database\PdoSmsLogger;
use SMSCountry\MessageType;
use SMSCountry\SMSCountryClient;
// Load .env manually if needed (or use vlucas/phpdotenv)
// putenv('SMS_COUNTRY_AUTH_KEY=...');
$config = Config::fromEnv();
$pdo = new PDO('mysql:host=127.0.0.1;dbname=myapp;charset=utf8mb4', 'root', 'secret');
$logger = new PdoSmsLogger($pdo, 'smscountry_logs');
$client = new SMSCountryClient($config, logger: $logger);
// Local number — country code 91 is added automatically
$result = $client->send('9876543210', 'Hello from SMS Country!', MessageType::Normal);
echo 'Job ID: ' . $result->messageId . PHP_EOL;
echo 'Status: ' . ($result->success ? 'sent' : 'failed') . PHP_EOL;
use SMSCountry\Laravel\Facades\SMSCountry;
use SMSCountry\MessageType;
SMSCountry::send('9876543210', 'Your OTP is 482910', MessageType::Normal);
use SMSCountry\Contracts\SMSCountryClientInterface;
use SMSCountry\MessageType;
class OtpController extends Controller
{
public function __construct(private SMSCountryClientInterface $sms) {}
public function sendOtp(Request $request)
{
$result = $this->sms->send(
mobileNumber: $request->phone, // e.g. 9876543210
message: 'Your OTP is 482910. Valid for 5 minutes.',
type: MessageType::Normal,
);
return response()->json([
'job_id' => $result->messageId,
'status' => 'sent',
]);
}
}
use SMSCountry\Laravel\Models\SmsLog;
$logs = SmsLog::query()
->where('status', 'sent')
->latest()
->paginate(20);
use SMSCountry\Config;
use SMSCountry\SMSCountryClient;
public static function smsCountry(bool $getShared = true)
{
if ($getShared) {
return static::getSharedInstance('smsCountry');
}
return new SMSCountryClient(Config::fromEnv([
'SMS_COUNTRY_AUTH_KEY' => env('SMS_COUNTRY_AUTH_KEY'),
'SMS_COUNTRY_AUTH_TOKEN' => env('SMS_COUNTRY_AUTH_TOKEN'),
'SMS_COUNTRY_BASE_URL' => env('SMS_COUNTRY_BASE_URL'),
'SMS_COUNTRY_SENDER_ID' => env('SMS_COUNTRY_SENDER_ID'),
'SMS_COUNTRY_DEFAULT_COUNTRY_CODE' => env('SMS_COUNTRY_DEFAULT_COUNTRY_CODE'),
]));
}
$sms = service('smsCountry');
$sms->send('9876543210', 'Hello from CodeIgniter!');
public function __construct(
private SMSCountryClientInterface $sms,
) {}
public function notify(string $phone, string $message): void
{
$this->sms->send($phone, $message);
}
use SMSCountry\Support\DeliveryWebhookHandler;
$handler = new DeliveryWebhookHandler($logger);
$handler->handle($_GET);
// Params: jobno, mobilenumber, status, doneTime, messagepart
use Illuminate\Http\Request;
use SMSCountry\Support\DeliveryWebhookHandler;
Route::get('/sms/delivery-callback', function (Request $request) {
app(DeliveryWebhookHandler::class)->handle($request->query());
return response('OK', 200);
});
use SMSCountry\MessageType;
$client->send('9876543210', 'नमस्ते', MessageType::Unicode);
$client->send('9876543210', 'Your OTP: 482910', MessageType::Normal);
use SMSCountry\DeliveryStatus;
$status = DeliveryStatus::Delivered;
echo $status->label(); // "Delivered"
bash
composer
bash
mysql -u root -p your_database < vendor/pratiksahu2003/smscountry-php-sdk/database/schema/smscountry_logs.sql