Skip to content

About

Official PHP library for OxiSMS. Send SMS messages in minutes from your projects.

Topics

Resources

Stars

3 stars

Watchers

2 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

Repository files navigation

Official OxiSMS PHP Wrapper

MIT License Current Version

Overview

This repository contains the official PHP wrapper for the OxiSMS API. You don't have to know how the API works to use it: every route is available through PHP objects documented with PHPDoc.

To get started, create an account on account.oxemis.com (a free trial is available).

What is OxiSMS?

OxiSMS is a solution designed to let you send your SMS quickly and easily, from our web application, our software, or your own programs with this library.

We offer worldwide coverage and sender personalization when it is allowed by the operators of your recipients (see the destinations). All our SMS are sent via Premium routes, for the best possible deliverability.

We're a small team, but we're recognized for the quality of our support and expertise.

Table of contents

Requirements

  • PHP 8.1 or higher, with the json extension;
  • Guzzle 7.8 or higher (installed by Composer).

Installation

composer require oxemis/oxisms

Quick start

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;
use Oxemis\OxiSms\Objects\Message;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

$message = (new Message())
    ->addRecipientPhoneNumber("+33600000001")
    ->setMessage("Hi there! This is my first SMS sent with the oxisms-php library.");

$sending = $client->sendAPI->send($message);
echo "Sending ID: " . $sending->getSendingId() . ", cost: " . $sending->getTotalCost() . " credit(s)\n";

Authentication and client options

You can create your API keys in your Oxemis account. We recommend keeping them out of your code, in environment variables:

export OXISMS_API_LOGIN='your API login'
export OXISMS_API_PWD='your API password'
require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

// Optional settings (third parameter), all optional:
$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'), [
    'timeout'         => 30,          // maximum duration of a request, in seconds (default 30)
    'connect_timeout' => 10,          // maximum duration to connect, in seconds (default 10)
    'max_retries'     => 3,           // retries on "429 Too Many Requests", honoring Retry-After (default 3, 0 to disable)
    'user_agent'      => 'MyApp/2.0', // added at the end of the User-Agent header
    // 'base_url'     => 'https://api.oxisms.com',  // URL of the API
    // 'handler'      => $handlerStack,             // a Guzzle handler, for your tests (see below)
]);

The client gives access to every feature of the API through these properties:

Property What for
userAPI your account: company name, credits, rates
sendAPI send SMS now or later, compute their cost, list and cancel scheduled sendings
sendersAPI your custom senders
trackingAPI delivery status, replies of your recipients, statistics
historyAPI the sendings made on your account
blacklistsAPI your unsubscribe list (historical name)
bouncesAPI your bounce list (invalid numbers)
toolsAPI phone number analysis, URL shortener, health check of the API

Getting information about your account

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));
$user = $client->userAPI->getUser();

echo "Name: " . $user->getCompanyName() . "\n";
echo "Remaining credits: " . $user->getCreditsAmount() . "\n";

// Last day of validity of your credits, INCLUDED (null if they don't expire)
if ($user->getCreditsValidBefore() !== null) {
    echo "Valid until: " . $user->getCreditsValidBefore()->format('Y-m-d') . " (included)\n";
}
if (!$user->isCreditsValidOn()) {
    echo "Your credits have expired.\n";
}

// Rates: cost in credits of one SMS, per destination
foreach ($user->getRates() as $rate) {
    echo $rate['Country'] . " (+" . $rate['CountryCode'] . "): " . $rate['Cost'] . " credit(s)\n";
}
echo "France: " . $user->getRateForCountryCode(33) . " credit(s) per SMS\n";

getCredits() returns an integer (decimals dropped); getCreditsAmount() gives the exact balance, which may have decimals since some destinations cost more than one credit.

Sending SMS

Your first SMS

Build a Message, then send it with $client->sendAPI->send():

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;
use Oxemis\OxiSms\Objects\Message;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

$message = (new Message())
    ->addRecipientPhoneNumber("+33600000001")
    ->addRecipientPhoneNumber("+33600000002")
    ->setCampaignName("Welcome")   // optional, groups your sendings in your history and statistics
    ->setMessage("Hi there! This is my first SMS sent with the oxisms-php library.");

$sending = $client->sendAPI->send($message);

echo "Sending ID: " . $sending->getSendingId() . "\n";       // to follow it with trackingAPI
echo "Cost: " . $sending->getTotalCost() . " credit(s)\n";

foreach ($sending->getOKRecipients() as $recipient) {
    echo $recipient->getMSISDN() . ": message " . $recipient->getToken() . "\n";
}
foreach ($sending->getFilteredRecipients() as $recipient) {
    // FILTERED_UNSUBSCRIBED, FILTERED_BOUNCED or FILTERED_NOT_COVERED
    echo $recipient->getPhoneNumber() . " was removed: " . $recipient->getFilteredReason() . "\n";
}
foreach ($sending->getInvalidRecipients() as $recipient) {
    echo $recipient->getPhoneNumber() . " is not a valid number\n";
}

Phone numbers should be given in international format (+33600000001 or 33600000001); French national numbers (0600000001) are also accepted. If no valid recipient is left, nothing is sent and getSendingId() returns an empty string.

Customized messages

Every {{Name}} in the text is replaced by the meta data Name of each recipient:

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;
use Oxemis\OxiSms\Objects\Message;
use Oxemis\OxiSms\Objects\Recipient;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

$message = (new Message())
    ->addRecipient(new Recipient("+33600000001", ["Name" => "Joe", "ID" => 1]))
    ->addRecipient(new Recipient("+33600000002", ["Name" => "Jane", "ID" => 2]))
    ->setMessage("Hi {{Name}}! This is your ID: {{ID}}");

// Two messages in one call: "Hi Joe! This is your ID: 1" and "Hi Jane! This is your ID: 2"
$client->sendAPI->send($message);

If a merge field is missing for some recipients, the sending is refused with an OxiSmsException whose getReason() is UNKNOWN_MERGE_FIELDS (see Error handling).

Using a custom sender

By default, SMS are sent with a short code (36xxx in France for example). You can display your own sender instead:

  • an alphanumeric sender: 3 to 11 characters (letters A-Z, digits, spaces), with at least one letter. It must first be added to your senders and validated by our team;
  • a numeric sender: 3 to 15 digits.

Some operators don't accept custom senders: a short code is then used. With the commercial strategy, an unsubscribe mention is added to your message ("STOP au 36111" for example), which makes it longer.

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;
use Oxemis\OxiSms\Objects\Message;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

// 1. Add the sender (once): it stays pending until our team validates it
$result = $client->sendersAPI->addSenderWithDetails("MyShop");
if (!$result->isSuccess()) {
    print_r($result->getErrors());   // e.g. ["My Shop" => "Invalid sender: must be alphanumeric, no spaces, ..."]
}

// 2. Check its status
$senders = $client->sendersAPI->getSenders();
print_r($senders->getValidated());   // usable senders
print_r($senders->getPending());     // waiting for validation
print_r($senders->getBlocked());     // refused (contact the support to know why)

// 3. Use it
if ($senders->isValidated("MyShop")) {
    $message = (new Message())
        ->setSender("MyShop")
        ->addRecipientPhoneNumber("+33600000001")
        ->setMessage("Your order is ready!");
    $client->sendAPI->send($message);
}

// Remove a sender
$client->sendersAPI->deleteSender("OldName");

How many characters can I put in my message?

It depends on the encoding (see What is encoding?):

  • GSM (letters, digits, common punctuation and some accents): up to 160 characters per SMS;
  • Unicode (emojis, other accents such as ê...): up to 70 characters per SMS;
  • longer messages are sent as a long SMS of up to 8 parts, displayed as one message on the phone; each part then holds 153 characters (GSM) or 67 characters (Unicode), and costs one SMS.

Keep the default Message::ENCODING_AUTO: OxiSMS uses GSM when the text allows it, Unicode otherwise. You can force it with setEncoding(Message::ENCODING_GSM) (characters outside the GSM alphabet are replaced, ê becomes e) or setEncoding(Message::ENCODING_UNICODE). More details in the FAQ.

How many credits will a sending use?

Use getCostOfMessage(): nothing is sent and no credit is used.

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;
use Oxemis\OxiSms\Objects\Message;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

$message = (new Message())
    ->addRecipientPhoneNumber("+33600000001")
    ->addRecipientPhoneNumber("+32470000001")
    ->setMessage("Our sales start tomorrow!");

$cost = $client->sendAPI->getCostOfMessage($message);
echo "This sending will use " . $cost->getTotalCost() . " credit(s), you have " . $cost->getCredits() . "\n";
if ($cost->isInsufficientCredits()) {
    echo "Not enough credits: the sending would be refused.\n";
}
foreach ($cost->getOKRecipients() as $recipient) {
    echo $recipient->getMSISDN() . ": " . $recipient->getCost() . " credit(s), " . $recipient->getEncoding() . "\n";
}

You can also set a maximum with setMaxCreditsPerSending(): if the sending would cost more, it is refused.

$message->setMaxCreditsPerSending(1);

try {
    $client->sendAPI->send($message);
} catch (\Oxemis\OxiSms\OxiSmsException $e) {
    // Code 406: "Total credits needed to send the message (2) exceeds the MaxCreditsPerSending parameter (1)."
    echo $e->getCode() . ": " . $e->getMessage() . "\n";
}

Choosing the strategy

Strategy Use it for Restrictions
Commercial (default) marketing messages, i.e. anything that promotes your activities or events, even free ones Not sent after 9:00 p.m., before 8:00 a.m., on Sundays and public holidays. They are not rejected: they are automatically postponed to the next allowed period.
Notification notifications (password reset, two-factor code, appointment reminder...) None

Please be very careful selecting the strategy. Sending marketing messages with the "notification" strategy will probably get your account locked because of complaints from your recipients. See What strategy should I choose?

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;
use Oxemis\OxiSms\Objects\Message;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));
$twoFactorCode = random_int(100000, 999999);

$message = (new Message())
    ->setStrategy(Message::STRATEGY_NOTIFICATION)
    ->addRecipientPhoneNumber("+33600000001")
    ->setMessage("Here is your code to authenticate: " . $twoFactorCode);

$client->sendAPI->send($message);

Scheduling a sending

The date must be at least 5 minutes away and no more than 90 days away. The credits are used when the sending is scheduled and given back if you cancel it.

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;
use Oxemis\OxiSms\Objects\Message;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

$message = (new Message())
    ->addRecipientPhoneNumber("+33600000001")
    ->setMessage("Reminder: your appointment is tomorrow at 10:00.")
    ->setScheduledDateTime(new DateTime("+1 day 18:00"));
$sending = $client->sendAPI->send($message);

// List the scheduled sendings (null if there is none)
foreach ($client->sendAPI->getScheduled() ?? [] as $scheduled) {
    echo $scheduled->getSendingId() . " on " . $scheduled->getScheduledDateTime()?->format('Y-m-d H:i')
        . ": " . $scheduled->getNbSMS() . " SMS, " . $scheduled->getCost() . " credit(s)\n";
}

// Cancel one
$client->sendAPI->deleteScheduled($sending->getSendingId());

Letting your recipients reply

With the reply mode, your recipients can answer your SMS (a custom sender can't be used with it). See How does the response mode work?

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;
use Oxemis\OxiSms\Objects\Message;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

$message = (new Message())
    ->setAllowReply(true)
    ->addRecipientPhoneNumber("+33600000001")
    ->setMessage("Will you attend our meeting on Friday? Answer YES or NO.");
$sending = $client->sendAPI->send($message);

// Later: read the replies (see "Replies" below)
foreach ($client->trackingAPI->getRepliesForSending($sending->getSendingId()) as $reply) {
    echo $reply->getFrom() . " answered: " . $reply->getMessage() . "\n";
}

Shortening a URL

Short URLs save characters, and some URLs refused by the operators (other URL shorteners for example) are made safe:

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;
use Oxemis\OxiSms\Objects\Message;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

$url = $client->toolsAPI->shortenUrl("https://www.example.com/sales/2026/winter?utm_source=sms");
echo $url->getShortenedUrl() . "\n";       // with "https://"
echo $url->getShortenedUrlSMS() . "\n";    // without "https://": the one to put in your SMS

$message = (new Message())
    ->addRecipientPhoneNumber("+33600000001")
    ->setMessage("Our winter sales: " . $url->getShortenedUrlSMS());
$client->sendAPI->send($message);

Tracking your messages

Status of a sending

Each message gets a StatusState, which tells what its (many) status codes mean: delivered, pending (still on its way, or no delivery receipt yet), failed or unknown.

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;
use Oxemis\OxiSms\Objects\MessageStatus;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

foreach ($client->trackingAPI->getStatusBySendingId("abc1234def") as $status) {
    echo $status->getRecipient() . ": " . $status->getStatusState()
        . " (" . $status->getStatusDesc() . ")\n";
    if ($status->getStatusState() === MessageStatus::STATE_FAILED) {
        // ...
    }
}

// One message (token returned by send()), or every message sent to a number
$status = $client->trackingAPI->getStatusByToken("1234abc567");
$statuses = $client->trackingAPI->getStatusByRecipient("33600000001");

// Every possible status code, with its description
foreach ($client->trackingAPI->getStatusList() as $definition) {
    echo $definition->getStatusCode() . ": " . $definition->getStatusDescDetail() . "\n";
}

Status over a period (pagination)

You can get the status of every message sent over a period of up to 31 days (start included, end excluded). The results are paged (up to 10,000 messages per page). getStatusForPeriod() reads every page for you:

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

$start = new DateTime("2026-11-01 00:00:00");
$end = new DateTime("2026-12-01 00:00:00");

foreach ($client->trackingAPI->getStatusForPeriod($start, $end) as $status) {
    echo $status->getSentOn()?->format('Y-m-d H:i') . " " . $status->getRecipient() . ": " . $status->getStatusState() . "\n";
}

Or page by page, if you want to stop and resume later:

$after = null;
do {
    $page = $client->trackingAPI->getStatusPage($start, $end, $after, 1000);
    foreach ($page as $status) {
        // ...
    }
    $after = $page->getNextAfter();   // null on the last page
} while ($page->hasMore());

Replies

Replies are available for the messages sent with setAllowReply(true):

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

$replies = $client->trackingAPI->getRepliesForSending("abc1234def");   // replies to a sending
$replies = $client->trackingAPI->getRepliesForMessage("1234abc567");   // replies to one message
$replies = $client->trackingAPI->getRepliesForPeriod(                  // received over a period (31 days max)
    new DateTime("2026-11-01"),
    new DateTime("2026-11-08")
);

foreach ($replies as $reply) {
    echo $reply->getReceivedOn()?->format('Y-m-d H:i') . " " . $reply->getFrom() . ": " . $reply->getMessage() . "\n";
}

Statistics

Delivery counters per sending, already computed: use them instead of the status of each message whenever you need an overview.

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

// Some sendings...
$stats = $client->trackingAPI->getStatistics(["abc1234def", "ghi5678jkl"]);
// ...or every sending of a period (the period actually used is in getStartDate() / getEndDate())
$stats = $client->trackingAPI->getStatisticsForPeriod(new DateTime("2026-11-01"), new DateTime("2026-11-30"));

foreach ($stats as $sending) {
    echo $sending->getSendingId() . ": " . $sending->getNbDelivered() . "/" . $sending->getNbMessages()
        . " delivered, " . $sending->getNbFailed() . " failed, " . $sending->getNbPending() . " pending\n";
}
print_r($stats->getTotals());
print_r($stats->getSendingIdsNotFound());   // unknown sendings are not an error

History of your sendings

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;
use Oxemis\OxiSms\Components\HistoryAPI;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

// Without dates: the last 7 days
$history = $client->historyAPI->getHistory(
    new DateTime("2026-11-01"),
    new DateTime("2026-11-30"),
    HistoryAPI::TYPE_API              // optional: TYPE_ALL (default), TYPE_CAMPAIGN or TYPE_API
);

echo "From " . $history->getStartDate()?->format('Y-m-d') . " to " . $history->getEndDate()?->format('Y-m-d') . "\n";
foreach ($history as $sending) {
    echo $sending->getSentOn()?->format('Y-m-d H:i') . " " . $sending->getCampaign() . ": "
        . $sending->getTotalRecipients() . " recipient(s), " . $sending->getTotalCost() . " credit(s)\n";
}

// One sending (searched in the last 7 days unless you give the dates)
$sending = $client->historyAPI->getSending("abc1234def", new DateTime("2026-10-01"), new DateTime("2026-11-30"));

Unsubscribe list and bounce list

Numbers of your unsubscribe list (blacklistsAPI: recipients who answered STOP, or numbers you added) and of your bounce list (bouncesAPI: invalid numbers) are automatically removed from your sendings.

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;
use Oxemis\OxiSms\Objects\ExclusionEntry;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

// Numbers, indexed by their ID (null if the list is empty)
$numbers = $client->blacklistsAPI->getBlacklistedPhoneNumbers();

// Entries with the date they were added and their origin
$list = $client->blacklistsAPI->getBlacklistEntries();
foreach ($list as $entry) {
    echo $entry->getPhoneNumber() . " added on " . $entry->getDateAdded()?->format('Y-m-d')
        . ($entry->getSource() === ExclusionEntry::SOURCE_SMS ? " (answered STOP)" : " (added manually)") . "\n";
}
if ($list->isDetailsComplete() === false) {
    echo "Some details are not available yet, ask again later.\n";
}

// Only the numbers added since your last call
$newer = $client->blacklistsAPI->getBlacklistEntries($list->getLastId() ?? -1);

// Add or remove numbers (true if every number was accepted)
$client->blacklistsAPI->addPhoneNumberToBlacklist("+33600000001");
$result = $client->blacklistsAPI->addToBlacklist(["+33600000002", "+33600000003"]);
print_r($result->getOK());
print_r($result->getErrors());
$client->blacklistsAPI->removeFromBlacklist(["+33600000002"]);

// Same methods for the bounce list
$client->bouncesAPI->getBouncelistEntries();
$client->bouncesAPI->addPhoneNumberToBouncelist("+33600000009");
$client->bouncesAPI->deletePhoneNumberInBouncelist("+33600000009");

The numbers you add or remove are sent in the body of the requests, never in the URL (they are personal data).

Phone number analysis

Check the format of numbers before sending (their existence is not checked):

require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

// Second parameter: the country the numbers are called from, for numbers in national format (default "FR")
foreach ($client->toolsAPI->getPhoneNumbersInfo(["06.00.00.00.01", "+32470000001", "123"], "FR") as $info) {
    echo $info->getOriginalPhoneNumber() . " => " . $info->getMSISDN()
        . " (" . $info->getCountryISO() . ", " . ($info->isMobile() ? "mobile" : "not mobile") . ", "
        . ($info->isValid() ? "valid" : "invalid") . ")\n";
}

// Is the API up? (no authentication needed)
var_dump($client->toolsAPI->isApiHealthy());

Error handling

Every error is an Oxemis\OxiSms\OxiSmsException:

Method Content
getCode() the code sent by the API: the HTTP status (400, 401, 403, 404, 406...); 0 for a network error
getMessage() the message of the API, in English
getReason() a machine-readable reason, when there is one (UNKNOWN_MERGE_FIELDS)
getDetails() the details of the reason (e.g. which merge fields are missing, for how many recipients)
getHttpStatus() the HTTP status (null for a network error)
getResponseBody() the raw answer of the API
isNetworkError() true for a DNS error, a timeout, a refused connection (the original exception is in getPrevious())
require_once 'vendor/autoload.php';

use Oxemis\OxiSms\OxiSmsClient;
use Oxemis\OxiSms\OxiSmsException;
use Oxemis\OxiSms\Objects\Message;

$client = new OxiSmsClient(getenv('OXISMS_API_LOGIN'), getenv('OXISMS_API_PWD'));

$message = (new Message())
    ->addRecipientPhoneNumber("+33600000001")
    ->setMessage("Hi {{FirstName}}!");   // no meta data "FirstName" for this recipient

try {
    $client->sendAPI->send($message);
} catch (OxiSmsException $e) {
    if ($e->isNetworkError()) {
        echo "The API could not be reached: " . $e->getMessage() . "\n";
    } elseif ($e->getReason() === OxiSmsException::REASON_UNKNOWN_MERGE_FIELDS) {
        foreach ($e->getDetails() ?? [] as $detail) {
            echo "Missing " . $detail['Field'] . " for " . $detail['MissingFor'] . " recipient(s)\n";
        }
    } else {
        echo "Error " . $e->getCode() . ": " . $e->getMessage() . "\n";
    }
}

When the API answers 429 Too Many Requests, the request is retried automatically (max_retries option), after the delay given by its Retry-After header (up to 60 seconds).

Additions and removals that are partly refused are not exceptions: addToBlacklist(), addSenderWithDetails()... return a ListUpdateResult whose getErrors() lists the refused items. The historical methods that return a bool (addPhoneNumberToBlacklist(), addSender()...) return true only if every item was accepted.

Testing your code without calling the API

Give a Guzzle handler to the client to simulate the answers of the API:

require_once 'vendor/autoload.php';

use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Oxemis\OxiSms\OxiSmsClient;

$mock = new MockHandler([
    new Response(200, ['Content-Type' => 'application/json'], json_encode([
        'CompanyName' => 'ACME', 'Credits' => 100, 'CreditsValidBefore' => null, 'Rates' => [],
    ])),
]);
$client = new OxiSmsClient('login', 'password', ['handler' => HandlerStack::create($mock)]);

echo $client->userAPI->getUser()->getCompanyName();   // "ACME", without any request to the API

Upgrading from 1.0

Version 1.1 is compatible with 1.0: your code keeps working without change. It requires PHP 8.1 or higher. Some behaviors were bugs and are fixed (see the CHANGELOG):

  • $client->blacklistsAPI and $client->bouncesAPI now exist;
  • getBlacklistedPhoneNumbers() and getBouncedPhoneNumbers() now return the numbers (they always returned an empty list);
  • addPhoneNumberToBlacklist() now works, and the add/remove methods return true when the numbers were accepted;
  • the meta data of a recipient is no longer given to the next recipients without meta data;
  • getUser() no longer fails when your credits don't expire, send() no longer fails when no valid recipient is left;
  • network errors are now OxiSmsExceptions.

deleteEmailInBouncelist() is deprecated: use deletePhoneNumberInBouncelist().

Links

Contribute

Feel free to ask anything, and contribute to this project. To run the tests and the static analysis:

composer install
composer test
composer analyse

Need help? 👉 support@oxemis.com

About

Official PHP library for OxiSMS. Send SMS messages in minutes from your projects.

Topics

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages