<?php

$phone = "0788798558";
$studentUserName = "Admin";
$studentPass = "Demo student";
$parentPass = "KyleXy*";

// Check if the phone number starts with '0'
if (substr($phone, 0, 1) === '0') {
    // Replace the first '0' with '255'
    $primaryPhone = '255' . substr($phone, 1);
} else if(substr($phone, 0,3) === '255') {
	$primaryPhone = $phone;
} else {
	// Start with "255" then "$phone"
	$primaryPhone = "255".$phone;
}

$message = 'Student Login\nUsername: '.$studentUserName.'\n';
$message .= 'Password: '.$studentPass.'\n\n';  // Adding an empty line for separation
$message .= 'Parents Login\n';
$message .= 'Username: '.$phone.'\n';
$message .= 'Password: '.$parentPass;

// Send login credentials text
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://messaging-service.co.tz/api/sms/v1/text/single',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{"from":"Elimika", "to":"'.$primaryPhone.'",  "text": "'.$message.'", "reference": "aswqetgcv"}',
// CURLOPT_POSTFIELDS =>'{"from":"Elimika", "to":"'.$primaryPhone.'",  "text": "'.$message.'", "reference": "aswqetgcv"}',
CURLOPT_HTTPHEADER => array(
	'Authorization: Basic YmVyZWdlOmp5enQ5OHFxbnpkOWdIVg==',
	'Content-Type: application/json',
	'Accept: application/json'
),
));

$response = curl_exec($curl);

curl_close($curl);

echo "Response: " . $response;