ЁЯУ▒ рдиреЗрдкрд╛рд▓реА SMS рдмрдореНрдк
bulk ┬╖ Nepal
ЁЯЗ│ЁЯЗк +977 ┬╖ 10-99 рдиреЗрдкрд╛рд▓реА рдирдореНрдмрд░
0,
'sent' => 0,
'failed' => 0,
'invalid' => 0
];
// Helper: validate nepali mobile (basic 98, 97, 96... 10 digits after 977? just simple)
function isValidNepaliNumber($num) {
// clean: remove +977, spaces, dashes
$cleaned = preg_replace('/[\s\-]/', '', $num);
// optional +977 or 977 then exactly 10 digits? Usually 98XXXXXXXX
if (preg_match('/^(?:\+977|977)?(9[6-8]\d{8}|98\d{8})$/', $cleaned, $match)) {
return true;
}
// also allow 10 digits starting with 98, 97, 96 without country code
if (preg_match('/^(9[6-8]\d{8})$/', $cleaned)) return true;
return false;
}
function formatNumberForSms($raw) {
// strip spaces, dashes, and leading +977 or 977, ensure 10 digit mobile
$clean = preg_replace('/[\s\-]/', '', $raw);
// if starts with +977 or 977, remove it
$clean = preg_replace('/^(?:\+977|977)/', '', $clean);
// if now 10 digit Nepali mobile start with 98/97/96 return as 977 + number
if (preg_match('/^(9[6-8]\d{8})$/', $clean)) {
return '977' . $clean; // standard format with country code
}
return null; // invalid
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['bulk_phones']) && isset($_POST['sms_message'])) {
$rawPhones = $_POST['bulk_phones'];
$message = trim($_POST['sms_message']);
$message = mb_substr($message, 0, 160); // simple truncate to 1 SMS
// split lines, commas, spaces, etc.
$phoneLines = preg_split('/[,\n\r\s]+/', $rawPhones, -1, PREG_SPLIT_NO_EMPTY);
$uniquePhones = array_unique($phoneLines);
$deliveryReport['total'] = count($uniquePhones);
foreach ($uniquePhones as $line) {
$line = trim($line);
if (empty($line)) continue;
if (isValidNepaliNumber($line)) {
$formatted = formatNumberForSms($line);
// --- simulate SMS sending (real integration would replace this) ---
// In production, replace with actual API call (e.g., Sparrow, AakashSMS, etc.)
$success = false;
$apiResult = '';
// ************* MOCK GATEWAY SIMULATION **************
// pretend we call API: 90% chance success for demo
$rand = rand(1, 100);
if ($rand <= 90) { // 90% success
$success = true;
$apiResult = 'тЬЕ queued (demo)';
$deliveryReport['sent']++;
} else {
$apiResult = 'тЭМ provider error (mock)';
$deliveryReport['failed']++;
}
// build log
$smsLog[] = [
'number' => $formatted,
'original' => $line,
'status' => $success ? 'sent' : 'failed',
'message' => $apiResult,
'preview' => mb_substr($message, 0, 30) . (mb_strlen($message) > 30 ? 'тАж' : '')
];
} else {
$deliveryReport['invalid']++;
$smsLog[] = [
'number' => $line,
'original' => $line,
'status' => 'invalid',
'message' => 'тЭМ not a valid Nepali mobile',
'preview' => ''
];
}
}
// adjust totals if needed (invalid counted separately)
$deliveryReport['total'] = $deliveryReport['sent'] + $deliveryReport['failed'] + $deliveryReport['invalid'];
}
?>
= $deliveryReport['total'] ?>рдЬрдореНрдорд╛
= $deliveryReport['sent'] ?>рдкрдард╛рдЗрдпреЛ
= $deliveryReport['failed'] ?>рдлреЗрд▓
= $deliveryReport['invalid'] ?>рдЕрд╡реИрдз рдирдореНрдмрд░
= htmlspecialchars($log['original']) ?>
тЖТ = htmlspecialchars($log['message']) ?>
тАЬ= htmlspecialchars($log['preview']) ?>тАЭ