PHPackages                             prinx/txtconnect - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. prinx/txtconnect

ActiveLibrary[API Development](/categories/api)

prinx/txtconnect
================

TxtConnect PHP SDK

v3.0.1(3y ago)08MITPHP

Since May 18Pushed 3y ago1 watchersCompare

[ Source](https://github.com/prinx/txtconnect-php)[ Packagist](https://packagist.org/packages/prinx/txtconnect)[ RSS](/packages/prinx-txtconnect/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (6)Dependencies (10)Versions (7)Used By (0)

[![](https://camo.githubusercontent.com/57e7dc3577f44f20c513fd93f7ebf131996eb6bb7c32ae875916a5594c49003f/68747470733a2f2f7777772e747874636f6e6e6563742e6e65742f6173736574732f54585420636f6e6e656374322f54585420636f6e6e656374322f74787420636f6e6e656374325f5247422e706e67)](https://txtconnect.net)

[![Build Status](https://camo.githubusercontent.com/d360539f432e1fffe0727aa7fccbe6d36928c691b85d2e4dd40bf979f4a9b7f0/68747470733a2f2f7472617669732d63692e636f6d2f7072696e782f747874636f6e6e6563742d7068702e7376673f6272616e63683d6d61696e)](https://travis-ci.com/prinx/txtconnect-php)[![Latest Stable Version](https://camo.githubusercontent.com/fcdbf1176a4624a56a6a10b08a86a231207344ff50639ffc355adced51e8d6f2/68747470733a2f2f706f7365722e707567782e6f72672f7072696e782f747874636f6e6e6563742f762f737461626c652e737667)](https://packagist.org/packages/prinx/txtconnect)[![License](https://camo.githubusercontent.com/dc0485c22eb3192ce8737821de5106136e24c0e1a83478cda19af87e25e02071/68747470733a2f2f706f7365722e707567782e6f72672f7072696e782f747874636f6e6e6563742f6c6963656e73652e737667)](https://packagist.org/packages/prinx/txtconnect)[![StyleCI](https://camo.githubusercontent.com/3df191104babb1f4daf54920c7c24ab89d6b5ee71be68c4d1db75648c294e4b8/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3336323532373134342f736869656c643f7374796c653d666c6174266272616e63683d6d61696e)](https://github.styleci.io/repos/362527144?branch=main)

TXTCONNECT PHP SDK
==================

[](#txtconnect-php-sdk)

TXTCONNECT is a platform that allows you to send SMS and voice messages to your specified contact list.

This package provides a convenient way of interacting with TXTCONNECT's API. It allows you to send SMS, check your SMS status, get your SMS inbox, check your account balance, without worrying about direct API calls.

- Create your TXTCONNECT account [here](https://txtconnect.net/signup);
- Then request for a [sender ID](https://txtconnect.net/customers/sender-ids-management);
- And generate an [API key](https://txtconnect.net/customers/campaigns-api/sms/user-sms-api-info).

Then you are ready to go.

Installation
------------

[](#installation)

```
composer require prinx/txtconnect
```

Usage
-----

[](#usage)

### Configuration

[](#configuration)

Create a `.env` file at the root of your project (where the vendor folder is located), if none exists already.

In the `.env` file specify your TxtConnect API credentials:

```
TXTCONNECT_KEY="api_key"
TXTCONNECT_SENDER_ID="sender_id"
```

### Sending SMS

[](#sending-sms)

```
require 'path/to/vendor/autoload.php'; // Not needed if using the package inside a framework.

use Prinx\Txtconnect\Sms;

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

$sms = new Sms;

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

#### Specifying the HTTP method

[](#specifying-the-http-method)

```
use Prinx\Txtconnect\Sms;

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

$sms = new Sms;

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

#### Number formats

[](#number-formats)

The number is automatically sanitized, any space, parenthesis, hyphen, is removed. This allows to pass the number without worrying about the correct format.

For example:

- +233 24 24 24 242
- 233(0)24 24 24 242
- 233 24 24-24-242
- etc

The only constraint is the number has to be in an international format. This constraint can be ignored by specifying a default country.

#### Specifying the default country

[](#specifying-the-default-country)

Specifying a default country allows to send SMS without worrying if the number is in international format or not. The package will automatically resolve and put the number in required format. For example, after specifying the default country as `Ghana`, you can send SMS to the number like 020 00 00 000, without putting it in international format.

```
$sms = new Sms();

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

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

#### Sending SMS to more than one number

[](#sending-sms-to-more-than-one-number)

You can send SMS to many numbers at once just by adding the numbers as an array to the `send` method:

```
$sms = new Sms();

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

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

#### Using the `to` method

[](#using-the-to-method)

The phone numbers can be passed to the sms instance ahead of time, before calling the `send` method:

```
$sms = new Sms();

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

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

And for more numbers:

```
$sms = new Sms();

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

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

or

```
$sms = new Sms();

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

$message = 'Hi';

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

or

```
$sms = new Sms();

$message = 'Hi';

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

#### Handling duplicate

[](#handling-duplicate)

By default, the package handles automatically duplicate numbers and does not send sms to duplicate numbers (unless it is explicitly activated).

##### Sending to duplicate

[](#sending-to-duplicate)

If you wish to send sms to duplicate numbers, you can activate it by calling the `keepDuplicate` method on the sms instance.

```
$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.
```

##### Deactivate sending to duplicate

[](#deactivate-sending-to-duplicate)

If you wish to send sms to duplicate numbers, you can activate it by calling the `removeDuplicate` method on the sms instance.

```
$sms = new Sms();

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

$message = 'Hi';

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

#### Invalid numbers

[](#invalid-numbers)

Sms will not be forwarded to invalid numbers.

Invalid numbers are:

- a number for which the package is not able to determine the country;
- a number that is not a phone number;
- a number that cannot receive an sms (a fixed phone number, for example).

This allows you not to waste bandwidth to make HTTP request to numbers that will not get the message you are sending and at the same time allows not to waste you TXTCONNECT balance.

### SMS response

[](#sms-response)

After sending an SMS, the response let you know if the SMS has been received by TXTCONNECT or if an error happened.

#### Single SMS response

[](#single-sms-response)

When sending an SMS to only one contact, the `send` method will return an `SmsResponse` instance:

```
$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();

    // ...
}
```

#### Multiple SMS response (SmsResponseBag)

[](#multiple-sms-response-smsresponsebag)

When sending SMS to multiple contacts, the `send` method will return an `SmsResponseBag` containing the `SmsResponse` of every contact:

```
$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);
//...
```

The first and last response can be accessed using the `first` and `last` method:

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

#### Forcing SmsResponseBag

[](#forcing-smsresponsebag)

You can force the `send` method to always return a `SmsResponseBag` weither the SMS has been sent to only one number or multiple numbers by calling the `asBag` method on the sms instance:

```
$sms = new Sms();

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

$smsResponse = $response->first();

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

### Get SMS status

[](#get-sms-status)

```
require 'path/to/vendor/autoload.php'; // Not needed if using the package inside a framework.

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.
```

#### Get Status of many SMS at a go

[](#get-status-of-many-sms-at-a-go)

```
require 'path/to/vendor/autoload.php'; // Not needed if using the package inside a framework.

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();
```

##### Adding batch number one by one

[](#adding-batch-number-one-by-one)

Batch numbers can be added one by one instead of passing all as an array to the `of` method:

```
$status = new SmsStatus();

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

##### Fluent interface

[](#fluent-interface)

The `SmsStatus` class implement a fluent interface, so the `of` method can be chained:

```
$status = new SmsStatus();

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

##### Using `first` and `last`

[](#using-first-and-last)

The `SmsStatus` class also extends the SmsBagAbstract, so when retrieveing statuses of more than one batch numbers, the first and last elements can be retrieved using the `first` and `last` method:

```
$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();
```

##### All the statuses fetched

[](#all-the-statuses-fetched)

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

$allFetchedStatusesAsArray = $status->toArray();
```

##### Count number of statuses fetched

[](#count-number-of-statuses-fetched)

```
$numberOfStatusesFetched = $status->count();
```

### Get Balance

[](#get-balance)

```
require 'path/to/vendor/autoload.php'; // Not needed if using the package inside a framework.

use Prinx\Txtconnect\Balance;

$balance = new Balance();

$amount = $balance->amount();
```

### Get SMS Inbox

[](#get-sms-inbox)

```
require 'path/to/vendor/autoload.php'; // Not needed if using the package inside a framework.

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.
```

Contributing
------------

[](#contributing)

- Give a ⭐ to the repo, it's free 😁
- Fork the repo;
- correct a bug, add a feature;
- and create a pull request.

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~120 days

Recently: every ~150 days

Total

6

Last Release

1271d ago

Major Versions

v1.2.0 → v2.0.02023-01-06

v2.0.0 → v3.0.02023-01-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/896d24b4882562faf6f1c8c25ea90e515037f5811f251a11fd80b68db61fc458?d=identicon)[Prinx](/maintainers/Prinx)

---

Top Contributors

[![prinx](https://avatars.githubusercontent.com/u/7337610?v=4)](https://github.com/prinx "prinx (195 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/prinx-txtconnect/health.svg)

```
[![Health](https://phpackages.com/badges/prinx-txtconnect/health.svg)](https://phpackages.com/packages/prinx-txtconnect)
```

###  Alternatives

[bitrix24/b24phpsdk

An official PHP library for the Bitrix24 REST API

10244.2k5](/packages/bitrix24-b24phpsdk)[storyblok/php-management-api-client

Storyblok PHP Client for Management API

1233.5k3](/packages/storyblok-php-management-api-client)[sproutcms/cms

Enterprise content management and framework

242.2k4](/packages/sproutcms-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
