jandreasn/an-sms

A PHP library to send and receive SMS text messages through various providers/gateways.

0.5.2 2018-12-13 08:40 UTC

README

Version Build Status

An extendable library for sending and receiving SMS messages. Currently comes packaged with these gateway providers:


Send SMS Delivery reports Receive SMS Premium SMS
46elks
Cellsynt
Nexmo
Twilio
Telenor SMS Pro

You can add and use your own gateway provider. This library enables easy switching between different gateways.

Installation

Add the package as a requirement to your composer.json:

$ composer require jandreasn/an-sms php-http/guzzle6-adapter php-http/message

Why php-http/guzzle6-adapter php-http/message? This package requires a php-http client implementation. You can install this one, an adapter for a client you are already using or another one. There are several adapters available. Read more about this in the HTTPlug docs.

If you want to use the Twilio gateway provider you also need to install the Twilio SDK:

$ composer require twilio/sdk

If you want to use the Nexmo gateway provider you also need to install the Nexmo client:

$ composer require nexmo/client

Usage

<?php

use AnSms\{
    SmsTransceiver,
    Message\Message,
    Message\PremiumMessage,
    Gateway\Provider\CellsyntGateway
};

$gateway = new CellsyntGateway('username', 'password');
$smsTransceiver = new SmsTransceiver($gateway);

// Send SMS
$message = Message::create('46700123456', 'Hello world!');
$smsTransceiver->sendMessage($message);

// Receive SMS
$receivedMessage = $smsTransceiver->receiveMessage($_GET);

// Receive SMS delivery report
$deliveryReport = $smsTransceiver->receiveDeliveryReport($_GET);

// Send Premium SMS
$premiumMessage = PremiumMessage::createFromIncomingMessage(
    'Thanks for your payment!', 
    5, 
    $receivedMessage
);
$smsTransceiver->sendMessage($premiumMessage);

Requirements

  • Requires PHP 7.1 or above.

Author

Andreas Nilsson (http://github.com/jandreasn)

License

This software is licensed under the MIT license - see the LICENSE file for details.