Search by

byjg / sms-client

byjg

A lightweight, extensible PHP library for sending SMS messages through multiple providers.

Package info

github.com/byjg/php-sms-client

pkg:composer/byjg/sms-client

Statistics

Installs: 9 996

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

6.0.0 2025-11-24 18:05 UTC

This package is auto-updated.

Last update: 2026-10-25 23:50:20 UTC


README

sidebar_key sms-client
sidebar_category messaging
tags
php sms

SMS Client

One interface to send SMS through any provider, and the right provider chosen by the phone number's country.

Sponsor Build Status Opensource ByJG Install MCP Server GitHub source GitHub license GitHub release

Why

SMS providers differ by country: one is cheap or reliable in the US, another in Brazil. Each has its own SDK, so supporting two means two code paths, and the choice is spread wherever a message is sent.

SMS Client puts the providers behind one interface, chosen by the connection URI, and can route each message by the destination country:

ProviderFactory::registerServices("twilio://accountId:authToken@default", "+1");
ProviderFactory::registerServices("byjg://username:password@default", "+55");

ProviderFactory::createAndSend("+12221234567", new Message("Hello USA!"));      // Twilio
ProviderFactory::createAndSend("+5521987654321", new Message("Olá Brasil!"));   // ByJG

Phone numbers are validated and formatted per country, and a new provider is one class.

Features

  • Low code - Simple, intuitive API for sending SMS
  • Provider agnostic - Support for multiple SMS providers
  • Extensible - Easy to implement custom providers
  • Phone formatting - Built-in phone number validation and formatting
  • Multi-provider support - Route messages to different providers based on country codes

Installation

composer require byjg/sms-client

Quick Start

use ByJG\SmsClient\Message;
use ByJG\SmsClient\Provider\ProviderFactory;
use ByJG\SmsClient\Provider\TwilioMessagingProvider;
use ByJG\Util\Uri;

// Register and create provider
ProviderFactory::registerProvider(TwilioMessagingProvider::class);
$provider = ProviderFactory::create(new Uri("twilio://$accountSid:$authToken@default"));

// Send message
$response = $provider->send(
    "+12221234567",
    (new Message("Hello World!"))->withSender("+12223217654")
);

// Check result
if ($response->isSent()) {
    echo "Message sent successfully!";
}

Documentation

Available Providers

Provider URI Scheme Documentation Region
Twilio Messaging twilio://accountId:authToken@default Twilio SMS Global
Twilio Verify twilio_verify://accountId:authToken@serviceSid Twilio Verify Global
ByJG SMS byjg://username:password@default ByJG Brazil
Fake Sender fakesender:// Testing only Testing

Multi-Provider Setup

Route messages to different providers based on country codes:

use ByJG\SmsClient\Provider\ProviderFactory;
use ByJG\SmsClient\Provider\TwilioMessagingProvider;
use ByJG\SmsClient\Provider\ByJGSmsProvider;
use ByJG\SmsClient\Message;

// Register providers
ProviderFactory::registerProvider(TwilioMessagingProvider::class);
ProviderFactory::registerProvider(ByJGSmsProvider::class);

// Associate with country codes
ProviderFactory::registerServices("twilio://accountId:authToken@default", "+1");
ProviderFactory::registerServices("byjg://username:password@default", "+55");

// Automatically routes to the right provider
ProviderFactory::createAndSend("+12221234567", new Message("Hello USA!"));
ProviderFactory::createAndSend("+5521987654321", new Message("Olá Brasil!"));

Phone Number Formatting

Format and validate phone numbers with country-specific rules:

use ByJG\SmsClient\Phone;
use ByJG\SmsClient\PhoneFormat\USPhoneFormat;

$phone = Phone::phone("2345678900", new USPhoneFormat())
    ->withPlusPrefix()
    ->withCountryCode();

echo $phone->hydrate();  // Output: +12345678900
echo $phone->format();   // Output: +1(234)567-8900

// Validate phone numbers
$isValid = $phone->validate(throwException: false);

Running Tests

vendor/bin/phpunit

Open source ByJG