PHP code example of ongudidan / textsms

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

    

ongudidan / textsms example snippets




use TextSms\Sms;

$partnerID = '1234';
$apiKey = 'your_api_key';
$shortcode = 'SMS';

// Send an SMS
$response = Sms::send($partnerID, $apiKey, $shortcode, '254712345678', 'Hello from PHP!');
print_r($response);

namespace App\Services;

use TextSms\Sms;

class SmsService
{
    protected $partnerID;
    protected $apiKey;
    protected $shortcode;

    public function __construct()
    {
        $this->partnerID = config('services.textsms.partner_id');
        $this->apiKey = config('services.textsms.api_key');
        $this->shortcode = config('services.textsms.shortcode');
    }

    public function send($mobile, $message)
    {
        return Sms::send($this->partnerID, $this->apiKey, $this->shortcode, $mobile, $message);
    }
}

use App\Services\SmsService;

public function checkout(SmsService $sms)
{
    $sms->send('254712345678', 'Order Received!');
}

namespace common\components;

use Yii;
use yii\base\Component;
use TextSms\Sms;

class SmsComponent extends Component
{
    public $partnerID;
    public $apiKey;
    public $shortcode;

    public function send($mobile, $message)
    {
        return Sms::send($this->partnerID, $this->apiKey, $this->shortcode, $mobile, $message);
    }
}

'components' => [
    'sms' => [
        'class' => 'common\components\SmsComponent',
        'partnerID' => '...',
        'apiKey' => '...',
        'shortcode' => '...',
    ],
],

Yii::$app->sms->send('254123456789', 'Hello from Yii!');

Sms::send($partnerID, $apiKey, $shortcode, $mobile, $message);

Sms::balance($partnerID, $apiKey);

Sms::status($partnerID, $apiKey, $messageId);