Practical PHP examples for the ASPSMS WebAPI (https://webapi.aspsms.com). Structure matches the WebAPI overview.
<?php
function checkCredentials(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/CheckUserCredentials?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
?>
<?php
function getCredits(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/ASPSMSCredits?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
<?php
function estimateCredits(string $userkey, string $password, array $msisdns): string {
$url = 'https://webapi.aspsms.com/ASPSMSEstimateCreditConsumption?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password
]);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode($msisdns)
]);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
<?php
function sendSimpleSms(string $userkey, string $password, string $msisdn, string $message, string $originator): string {
$url = 'https://webapi.aspsms.com/SendSimpleSMS?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password, 'MSISDN' => $msisdn,
'Operation' => 'SendTextSMS', 'MessageData' => $message, 'Originator' => $originator
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
<?php
function sendAdvancedSms(string $userkey, string $password, string $message, string $originator, array $recipients): string {
$url = 'https://webapi.aspsms.com/ASPSMSSendSMS?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$payload = ['Operation' => 'SendTextSMS', 'Originator' => $originator, 'MessageData' => $message, 'Recipients' => $recipients];
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode($payload)
]);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
Same originator for all, individual text (and optional TRN / deferred time) per recipient.
<?php
function sendPersonalizedSms(string $userkey, string $password, string $originator, array $messages): string {
// $messages e.g.:
// [
// ['PhoneNumber' => '+41791111111', 'TransactionReferenceNumber' => 'ORDER-1001',
// 'MessageData' => 'Hi Anna, your order #1001 is on the way.'],
// ['PhoneNumber' => '+41792222222', 'TransactionReferenceNumber' => 'ORDER-1002',
// 'MessageData' => 'Hi Bruno, your order #1002 is on the way.',
// 'DeferredDeliveryTime' => '2026-10-20T08:00:00'] // optional per recipient
// ]
$url = 'https://webapi.aspsms.com/ASPSMSSendSMS?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$payload = [
'Operation' => 'SendTextSMS',
'Originator' => $originator, // same for all
'RecipientsEx' => $messages // individual MessageData per recipient
];
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode($payload)
]);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
<?php
function deactivateByMsisdn(string $userkey, string $password, array $msisdns): string {
$url = 'https://webapi.aspsms.com/ASPSMSDeactivatePendingSMSWithMSISDN?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$ch = curl_init($url);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_POSTFIELDS => json_encode($msisdns)]);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
<SCTS>, <DSCTS>, <RSN>, <DST>, <TRN>, <RCPNT>, <CREDITS> (max. 200 chars per URL).<?php
function sendSmsWithWebhooks(string $userkey, string $password, string $message, string $originator, array $recipients): string {
$url = 'https://webapi.aspsms.com/ASPSMSSendSMS?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$payload = [
'Operation' => 'SendTextSMS', 'Originator' => $originator, 'MessageData' => $message, 'Recipients' => $recipients,
'URLBufferedMessageNotification' => 'https://your-domain.com/hook/buffered?SCTS=<SCTS>&DSCTS=<DSCTS>&RSN=<RSN>&DST=<DST>&TRN=<TRN>&RCPNT=<RCPNT>',
'URLDeliveryNotification' => 'https://your-domain.com/hook/delivered?SCTS=<SCTS>&DSCTS=<DSCTS>&RSN=<RSN>&DST=<DST>&TRN=<TRN>&RCPNT=<RCPNT>',
'URLNonDeliveryNotification' => 'https://your-domain.com/hook/failed?SCTS=<SCTS>&DSCTS=<DSCTS>&RSN=<RSN>&DST=<DST>&TRN=<TRN>&RCPNT=<RCPNT>'
];
$ch = curl_init($url);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_POSTFIELDS => json_encode($payload)]);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
| Value | Meaning |
|---|---|
| -1 | Not yet submitted / rejected |
| 0 | Delivered |
| 1 | Buffered |
| 2 | Not Delivered |
After status 1 (Buffered) you almost always get a second call with 0 or 2.
| Code | Meaning | Typical cause |
|---|---|---|
| 000 | Unknown Subscriber | Number does not exist |
| 103 | Call Barred | Blocked / empty prepaid |
| 107 | Absent Subscriber | Phone off / no network |
| 108 | Delivery Fail | Memory full or final failure |
| 110 | Protocol Error | Device problems |
| 118 | System fail | Severe network/device issues |
<?php
function getTrafficStat(string $userkey, string $password, bool $calculateCredits = true): string {
$url = 'https://webapi.aspsms.com/TrafficStat01/Get?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password, 'CalculateCredits' => $calculateCredits ? 'true' : 'false'
]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getSendingLog(string $userkey, string $password, int $year, int $month = 0, int $day = 0): string {
$url = 'https://webapi.aspsms.com/SendingStat01/Get?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password, 'Year' => $year, 'Month' => $month, 'Day' => $day
]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
// SendingStat02 (MSISDN), SendingStat03 (TRN), SendingStat04 (JobID) – same GET pattern
function getLogByTrn(string $userkey, string $password, string $trn): string {
$url = 'https://webapi.aspsms.com/SendingStat03/Get?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password, 'TransactionReferenceNumber' => $trn
]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getReceivedSms(string $userkey, string $password, int $year = 0, int $month = 0, int $day = 0): string {
$url = 'https://webapi.aspsms.com/ReceivingStat01/Get?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password, 'Year' => $year, 'Month' => $month, 'Day' => $day, 'MaxRecords' => 100
]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function setReceiveUrl(string $userkey, string $password, string $callbackUrl): string {
$url = 'https://webapi.aspsms.com/ReceiveURL/Set?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password, 'URL' => $callbackUrl
]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getMsisdnDlrStat(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/MSISDNDLRStat/Get?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getPhonebook(string $userkey, string $password, ?string $msisdn = null): string {
$params = ['Userkey' => $userkey, 'Password' => $password];
if ($msisdn) $params['MSISDN'] = $msisdn;
$url = 'https://webapi.aspsms.com/PhoneNumbers/Read?' . http_build_query($params);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getGroups(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/Groups/Get?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getAllGroupRelations(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/GroupRelationsAll/Get?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
Document sending actions. Pass JobID when sending; query messages later via SendingStat04.
<?php
function getJobs(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/Jobs/Get?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getTemplates(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/Templates/Get?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>