PHP code example of prinx / txtconnect

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

    

prinx / txtconnect example snippets




use Prinx\Txtconnect\Sms;

$message = 'Hello World';
$number = '233...'; // See number formats below

$sms = new Sms;

$response = $sms->send($message, $number);

use Prinx\Txtconnect\Sms;

$method = 'POST'; // GET|POST

$sms = new Sms;

$response = $sms->send($message, $phone, $method);

$sms = new Sms();

$message = 'Hi';
$phone = '020 00 00 000';

$response = $sms->country('GH')->send($message, $phone);

$sms = new Sms();

$message = 'Hi';
$phones = ['233200000000', '233210000000', '233220000000'];

$response = $sms->send($message, $phones);

$sms = new Sms();

$message = 'Hi';
$phone = '233200000000';

$response = $sms->to($phone)->send($message);

$sms = new Sms();

$message = 'Hi';
$phones = ['233200000000', '233210000000', '233220000000'];

$response = $sms->to($phones)->send($message);

$sms = new Sms();

$sms->to('233200000000');
$sms->to('233210000001');
$sms->to('233220000002');

$message = 'Hi';

$response = $sms->send($message);

$sms = new Sms();

$message = 'Hi';

$response = $sms->to('233200000000')
        ->to('233210000001')
        ->to('233220000002')
        ->send($message);

$sms = new Sms();

$sms->to('233200000000');
$sms->to('233200000000');
$sms->to('233220000002');

$message = 'Hi';

$response = $sms->keepDuplicate()->send($message); // Sends to the first number twice then the third number.

$sms = new Sms();

$sms->to('233200000000');
$sms->to('233200000000');
$sms->to('233220000002');

$message = 'Hi';

$response = $sms->removeDuplicate()->send($message); // Sends to only two

$sms = new Sms();

$response = $sms->asUnicode()->send('Hi 😄', '233200000000');

$sms = new Sms();

$response = $sms->asPlainText()->send('Hi', '233200000000');

$sms = new Sms();

$response = $sms->send('Hi', '233200000000'); // $response is an SmsResponse instance

// If request received by TXTCONNECT
if ($response->isBeingProcessed()) {
    $batchNumber = $response->getBatchNumber();
    $statusCheckUrl = $response->getStatusCheckUrl();
    $availableBalance = $response->getBalance();

    // ...
} else {
    $error =  $response->getError();
    $rawResponse - $response->getRawResponse();

    // ...
}

$sms = new Sms();

$phone1 = '233200000000';
$phone2 = '233210000001';
$phone3 = '233220000002';

$response = $sms->send('Hi', [$phone1, $phone2, $phone3]); // $response is a SmsResponseBag instance

// Response for the first phone number
$response1 = $response->get($phone1);

if ($response1->isBeingProcessed()) {
    $batchNumber = $response1->getBatchNumber();
    $statusCheckUrl = $response1->getStatusCheckUrl();
    $availableBalance = $response1->getBalance();

    // ...
} else {
    $error =  $response1->getError();
    $rawResponse - $response1->getRawResponse();

    // ...
}

$response2 = $response->get($phone2);
// ...

$response3 = $response->get($phone3);
//...

$response1 = $response->first();
$response3 = $response->last();

$sms = new Sms();

$response = $sms->asBag()->send('Hi', '233200000000'); // Will return a SmsResponseBag

$smsResponse = $response->first();

if ($smsResponse->isBeingProcessed()) {
    // code
}




use Prinx\Txtconnect\SmsStatus;

$status = new SmsStatus();
$sms = $status->of($batchNumber)->get(); // Return an instance of SmsMessage

$isDelivered = $sms->isDelivered(); // Returns true if SMS has been delivered to recipient.



use Prinx\Txtconnect\SmsStatus;

$status = new SmsStatus();

$status->of([$batchNumber1, $batchNumber2, $batchNumber3]);

$sms1 = $status->get($batchNumber1);
$sms1IsDelivered = $sms1->isDelivered();

$sms2 = $status->get($batchNumber2);
$sms2IsDelivered = $sms2->isDelivered();

$sms3 = $status->get($batchNumber3);
$sms3IsDelivered = $sms3->isDelivered();

$status = new SmsStatus();

$status->of($batchNumber1);
$status->of($batchNumber2);
$status->of($batchNumber3);

$status = new SmsStatus();

$status->of($batchNumber1)
    ->of($batchNumber2)
    ->of($batchNumber3);

$status = new SmsStatus();

$status->of($batchNumber1)
    ->of($batchNumber2)
    ->of($batchNumber3);

$sms1 = $status->first();
$isSms1Delivered = $sms1->isDelivered();

$sms2 = $status->get($batchNumber2);
$isSms2Delivered = $sms2->isDelivered();

$sms3 = $status->last();
$isSms3Delivered = $sms3->isDelivered();

$allFetchedStatuses = $status->all(); // Array of SmsMessage

$allFetchedStatusesAsArray = $status->toArray();

$numberOfStatusesFetched = $status->count();



use Prinx\Txtconnect\Balance;

$balance = new Balance();

$amount = $balance->amount();



use Prinx\Txtconnect\Inbox;

$inbox = new Inbox();

$inboxCount = $inbox->count(); // Number of SMS in the fetched Inbox.

$allSmsToArray = $inbox->toArray(); // An array of all inbox SMS, each SMS being an array

$allSms = $inbox->all(); // Array of all inbox SMS, each SMS being a SmsMessage instance

$allSms = $inbox->get($phone); // Get an array of all SMS sent to this phone number

$sms = $inbox->nth(2); // Return the second SmsMessage of the inbox

$inbox->refresh(); // Prepare the inbox to be refetched.