<?php


    $json_url = "https://api.ebulksms.com/sendsms.json";
    $username = 'okolichikevitalis@gmail.com';
    $sendername = 'TRANSFMTION';
    
    function send_sms_msg($number, $apikey, $msg)
    {
        global $json_url, $username, $sendername;
        
        $responseArray = array(); // Array to store responses
        
        $number_array = explode(',', $number);
        $msg_array = explode('###,', $msg);
        $api_key_array = explode(',', $apikey);
    
        foreach ($number_array as $i => $f_number) {
            $f_number;
            $f_msg = $msg_array[$i];
    
            $apikeynew = $api_key_array[$i];
    
            $mobilenumber = trim($f_number);
    
            if (substr($mobilenumber, 0, 1) == '0') {
                $mobilenumber = $country_code . substr($mobilenumber, 1);
            } elseif (substr($mobilenumber, 0, 1) == '+') {
                $mobilenumber = substr($mobilenumber, 1);
            }
    
            $generated_id = uniqid('int_', false);
            $generated_id = substr($generated_id, 0, 30);
    
            $message = array(
                'sender' => $sendername,
                'messagetext' => $f_msg, // Use personalized message for each recipient
                'flash' => '0',
            );
    
            $gsm['gsm'] = array(
                'msidn' => $mobilenumber,
                'msgid' => $generated_id,
                'message' => $message
            );
    
            $request = array(
                'auth' => array(
                    'username' => $username,
                    'apikey' => $apikeynew
                ),
                'message' => $message,
                'recipients' => $gsm
            );
    
            $json_data = json_encode(array('SMS' => $request));
    
            $ch = curl_init();
    
            curl_setopt($ch, CURLOPT_URL, $json_url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            curl_setopt($ch, CURLOPT_HEADER, FALSE);
            curl_setopt($ch, CURLOPT_POST, TRUE);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
    
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    
            $response = curl_exec($ch);
            $responseArray[] = json_decode($response); // Store each response in the array
            curl_close($ch);
        }
        
        return $responseArray; // Return the array of responses
    }
    
    
?>