PHP code example of viontex / communications

1. Go to this page and download the library: Download viontex/communications 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/ */

    

viontex / communications example snippets


composer 

      php spark bulksms:publish
    

      php spark migrate --all
    

      app/Config/Validation.php
    

      public array $ruleSets = [
        Rules::class,
        FormatRules::class,
        FileRules::class,
        CreditCardRules::class,
        \Eddieodira\Messager\Validation\TemplateRules::class, // Bulk SMS rules goes here
    ];

## Registration
To use this library you need create an account with Hostpinnacle (https://www.hostpinnacle.co.ke). They will help to create account from which you will get the following credentials:

1. API End Point
2. User ID
3. Password
4. API Key
5. Sender ID

## Configuration
Inside the class, set the values provided by your SMS gateway:


// Via services 1
$bulksms = \Eddieodira\Messager\Config\Services::bulksms(); 
$bulksms->send(...);

//Or
use Eddieodira\Messager\Config\Services;
$bulksms = Services::bulksms();
$bulksms->send(...);

// Via services 2
$bulksms = service('bulksms');
$bulksms->send(...);

// Traditional way
$bulksms = new \Eddieodira\Messager\Bulksms();
$bulksms->send(...);

//Or
use Eddieodira\Messager\Bulksms;
$bulksms = new Bulksms();
$bulksms->send(...);

// Statically as
use Eddieodira\Messager\Facades\Bulksms;

Bulksms::send(...);

use Eddieodira\Messager\Bulksms;

$bulksms = new Bulksms();
$bulksms->send('2547xxxxxxxx', 'Hello, I am just testing this applications');

use Eddieodira\Messager\Bulksms;

$bulksms = new Bulksms();
$bulksms->send(['25472xxxxxxx, 25475xxxxxxx, 25476xxxxxxx'], 'Hello, I am just testing this applications');

use Eddieodira\Messager\Bulksms;

$bulksms = new Bulksms();
$bulksms->send(['25472xxxxxxx, 25475xxxxxxx, 25476xxxxxxx'], 'Hello, I am just testing this applications', '2026-04-25 09:46:00');

  use Eddieodira\Messager\Bulksms;

  $bulksms = new Bulksms();
  $sms = $bulksms->render('fees_increase', [
      'name'          => 'John Doe',
      'contact'       => 'Jane Doe',
      'organisation'  => '....' //Name of Organisation goes here
  ]);
  $bulksms->send(['254715070754', '254707362220'], $sms);

  use Eddieodira\Messager\Bulksms;

  $bulksms = new Bulksms();
  $extractedPlaceholders = $bulksms->extractPlaceholders('fees_increase');

  array (size=3)
  'name'          => string 'User' (length=4)
  'contact'       => string 'Representative' (length=14)
  'organisation'  => null

  use Eddieodira\Messager\Bulksms;

  $bulksms = new Bulksms();
  $bulksms->create(["code" => ..., "name" => ..., "content" => ...]);

  use Eddieodira\Messager\Bulksms;

  $bulksms = new Bulksms();
  $bulksms->update(["code" => ..., "name" => ..., "content" => ...], 2);

  use Eddieodira\Messager\Bulksms;

  $bulksms = new Bulksms();
  $sms = $bulksms->findTemplates();

  use Eddieodira\Messager\Bulksms;

  $bulksms = new Bulksms();
  $sms = $bulksms->findTemplate(1);

  use Eddieodira\Messager\Bulksms;

  $bulksms = new Bulksms();
  $sms = $bulksms->findByWhere('column', value);


declare(strict_types=1);

namespace Eddieodira\Messager\Config;

use CodeIgniter\Config\BaseConfig;

class Bulksms extends BaseConfig
{
    /**
     * Here you can set the connection that the email Teemplate should use when
     * storing and restoring a cart.
     */
    public string $emailTemplateTable = 'email_templates';

    /**
     * Here you can set the connection that the shoppingcart should use when
     * storing and restoring a cart.
    */
    public string $smsTemplateTable = 'sms_templates';

    /**
    * Unique identifier assigned to your HostPinnacle account.
    * Often xxxxxxxxxxxxxxxxxxxxxxxxx';

    /**
     * Sender ID that appears as the "from" field when recipients receive SMS.
     * It can be a name, brand, or shortcode registered with HostPinnacle.
     * Helps recipients identify the sender of the message.
     */
    public string $senderId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

    /**
     * Base URL of HostPinnacle’s SMS API.
     * All requests (send, bulk, balance, etc.) will be appended to this root URL.
     * Centralizing it here makes the library easier to maintain if the endpoint changes.
     */
    public string $baseUrl = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

    /**
     * Maximum time (in seconds) to wait for the entire request to complete.
     * If the API takes longer than this, the request will fail.
     * Helps prevent hanging requests in production.
     */
    public int $timeout = 10;

    /**
     * Maximum time (in seconds) to wait for the initial connection to the API server.
     * If the server cannot be reached within this time, the request will fail.
     * Useful for failing fast when the API endpoint is down.
     */
    public int $connectTimeout = 5;

    /**
     * Whether to verify SSL certificates when making requests.
     * Enabled in production for security, but automatically disabled in development
     * to allow local testing with self-signed certificates.
     */
    public bool $verify = (ENVIRONMENT !== 'development');

    /**
     * Whether HTTP errors (4xx/5xx) should throw exceptions automatically.
     * Disabled here so the library can handle errors manually and return
     * standardized responses instead of breaking execution.
     */
    public bool $httpErrors = false;

    /**
     * Whether to enable verbose debugging output for requests.
     * Enabled only in development mode to log request/response details
     * for troubleshooting, but disabled in production for performance and security.
     */
    public bool $debug = (ENVIRONMENT === 'development');