{"id":21141887,"url":"https://github.com/matthewbdaly/sms-client","last_synced_at":"2025-07-09T05:32:07.168Z","repository":{"id":15222761,"uuid":"77756321","full_name":"matthewbdaly/sms-client","owner":"matthewbdaly","description":"A generic SMS client library. Supports multiple swappable drivers.","archived":false,"fork":false,"pushed_at":"2022-03-14T09:56:46.000Z","size":108,"stargazers_count":21,"open_issues_count":0,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-13T02:49:01.914Z","etag":null,"topics":["php","php7","sms","sms-api","sms-client","sms-messages","sms-notifications"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matthewbdaly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-31T21:18:43.000Z","updated_at":"2024-05-13T15:14:59.000Z","dependencies_parsed_at":"2022-08-07T08:00:59.808Z","dependency_job_id":null,"html_url":"https://github.com/matthewbdaly/sms-client","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewbdaly%2Fsms-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewbdaly%2Fsms-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewbdaly%2Fsms-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewbdaly%2Fsms-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matthewbdaly","download_url":"https://codeload.github.com/matthewbdaly/sms-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225488486,"owners_count":17482289,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","php7","sms","sms-api","sms-client","sms-messages","sms-notifications"],"created_at":"2024-11-20T07:38:13.908Z","updated_at":"2024-11-20T07:38:14.824Z","avatar_url":"https://github.com/matthewbdaly.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sms-client\n[![Build Status](https://travis-ci.org/matthewbdaly/sms-client.svg?branch=master)](https://travis-ci.org/matthewbdaly/sms-client)\n\nA generic SMS client library. Supports multiple swappable drivers, so that you're never tied to just one provider.\n\nThis library is aimed squarely at sending SMS messages only, and I don't plan to add support for other functionality. The idea is to create one library that should be able to work with any provider that has a driver for the purpose of sending SMS messages.\n\nDrivers\n-------\n\nIt currently ships with the following drivers:\n\n* Clockwork\n* Nexmo\n* TextLocal\n* Twilio\n* AWS SNS (requires installation of `aws/aws-sdk-php`)\n* Mail (for mail-to-SMS gateways)\n* O2SK (O2 Slovakia)\n\nIn addition, it also has the following drivers for test purposes:\n\n* RequestBin\n* Null\n* Log\n\nThe RequestBin sends the POST request to the specified RequestBin path for debugging. The Null driver does nothing, while the Log driver accepts a PSR3 logger and uses it to log the request.\n\nExample Usage\n-----\n\n**Null**\n\n```php\nuse GuzzleHttp\\Client as GuzzleClient;\nuse GuzzleHttp\\Psr7\\Response;\nuse Matthewbdaly\\SMS\\Drivers\\Null;\nuse Matthewbdaly\\SMS\\Client;\n\n$guzzle = new GuzzleClient;\n$resp = new Response;\n$driver = new Null($guzzle, $resp);\n$client = new Client($driver);\n$msg = [\n    'to'      =\u003e '+44 01234 567890',\n    'content' =\u003e 'Just testing',\n];\n$client-\u003esend($msg);\n```\n\n**Log**\n\n```php\nuse Matthewbdaly\\SMS\\Drivers\\Log;\nuse Matthewbdaly\\SMS\\Client;\nuse Psr\\Log\\LoggerInterface;\n\n$driver = new Log($logger); // $logger should be an implementation of Psr\\Log\\LoggerInterface\n$client = new Client($driver);\n$msg = [\n    'to'      =\u003e '+44 01234 567890',\n    'content' =\u003e 'Just testing',\n];\n$client-\u003esend($msg);\n\n```\n\n**RequestBin**\n\n```php\nuse GuzzleHttp\\Client as GuzzleClient;\nuse GuzzleHttp\\Psr7\\Response;\nuse Matthewbdaly\\SMS\\Drivers\\RequestBin;\nuse Matthewbdaly\\SMS\\Client;\n\n$guzzle = new GuzzleClient;\n$resp = new Response;\n$driver = new RequestBin($guzzle, $resp, [\n    'path' =\u003e 'MY_REQUESTBIN_PATH',\n]);\n$client = new Client($driver);\n$msg = [\n    'to'      =\u003e '+44 01234 567890',\n    'content' =\u003e 'Just testing',\n];\n$client-\u003esend($msg);\n```\n\n**Clockwork**\n\n```php\nuse GuzzleHttp\\Client as GuzzleClient;\nuse GuzzleHttp\\Psr7\\Response;\nuse Matthewbdaly\\SMS\\Drivers\\Clockwork;\nuse Matthewbdaly\\SMS\\Client;\n\n$guzzle = new GuzzleClient;\n$resp = new Response;\n$driver = new Clockwork($guzzle, $resp, [\n    'api_key' =\u003e 'MY_CLOCKWORK_API_KEY',\n]);\n$client = new Client($driver);\n$msg = [\n    'to'      =\u003e '+44 01234 567890',\n    'content' =\u003e 'Just testing',\n];\n$client-\u003esend($msg);\n```\n\n**Nexmo**\n\n```php\nuse GuzzleHttp\\Client as GuzzleClient;\nuse GuzzleHttp\\Psr7\\Response;\nuse Matthewbdaly\\SMS\\Drivers\\Nexmo;\nuse Matthewbdaly\\SMS\\Client;\n\n$guzzle = new GuzzleClient;\n$resp = new Response;\n$driver = new Nexmo($guzzle, $resp, [\n    'api_key' =\u003e 'MY_NEXMO_API_KEY',\n    'api_secret' =\u003e 'MY_NEXMO_API_SECRET',\n]);\n$client = new Client($driver);\n$msg = [\n    'to'      =\u003e '+44 01234 567890',\n    'from'    =\u003e 'Test User',\n    'content' =\u003e 'Just testing',\n];\n$client-\u003esend($msg);\n```\n\n**AWS SNS**\n\n```php\nuse Matthewbdaly\\SMS\\Client;\nuse Matthewbdaly\\SMS\\Drivers\\Aws;\n\n$config = [\n    'api_key'    =\u003e 'foo',\n    'api_secret' =\u003e 'bar',\n    'api_region' =\u003e 'ap-southeast-2'\n];\n$driver = new Aws($config);\n$client = new Client($driver);\n$msg = [\n    'to'      =\u003e '+44 01234 567890',\n    'from'    =\u003e 'Test User',\n    'content' =\u003e 'Just testing',\n];\n$client-\u003esend($msg);\n```\n\n**Mail**\n\n```php\nuse Matthewbdaly\\SMS\\Client;\nuse Matthewbdaly\\SMS\\Drivers\\Mail;\nuse Matthewbdaly\\SMS\\Contracts\\Mailer;\n\n$config = [\n    'domain' =\u003e 'my.sms-gateway.com'\n];\n$driver = new Mail($config);\n$client = new Client($driver);\n$msg = [\n    'to'      =\u003e '+44 01234 567890',\n    'content' =\u003e 'Just testing',\n];\n$client-\u003esend($msg);\n```\n\n**TextLocal**\n\n```php\nuse GuzzleHttp\\Client as GuzzleClient;\nuse GuzzleHttp\\Psr7\\Response;\nuse Matthewbdaly\\SMS\\Drivers\\TextLocal;\nuse Matthewbdaly\\SMS\\Client;\n\n$guzzle = new GuzzleClient;\n$resp = new Response;\n$driver = new TextLocal($guzzle, $resp, [\n    'api_key' =\u003e 'MY_TEXTLOCAL_API_KEY',\n]);\n$client = new Client($driver);\n$msg = [\n    'to'      =\u003e '+44 01234 567890',\n    'from'    =\u003e 'Test User',\n    'content' =\u003e 'Just testing',\n];\n$client-\u003esend($msg);\n```\n\n**Twilio**\n\n```php\nuse GuzzleHttp\\Client as GuzzleClient;\nuse GuzzleHttp\\Psr7\\Response;\nuse Matthewbdaly\\SMS\\Drivers\\Twilio;\nuse Matthewbdaly\\SMS\\Client;\n\n$guzzle = new GuzzleClient;\n$resp = new Response;\n$driver = new Twilio($guzzle, $resp, [\n    'account_id' =\u003e 'MY_TWILIO_ACCOUNT_ID',\n    'api_token' =\u003e 'MY_TWILIO_API_TOKEN',\n]);\n$client = new Client($driver);\n$msg = [\n    'to'      =\u003e '+44 01234 567890',\n    'from'      =\u003e '+44 01234 567890',\n    'content' =\u003e 'Just testing',\n];\n$client-\u003esend($msg);\n```\n\n**O2SK**\n\n```php\nuse GuzzleHttp\\Client as GuzzleClient;\nuse Matthewbdaly\\SMS\\Drivers\\O2SK;\nuse Matthewbdaly\\SMS\\Client;\n\n$driver = new O2SK(new GuzzleClient, [\n    'apiKey' =\u003e 'MY_O2SK_API_KEY',\n]);\n$client = new Client($driver);\n$msg = [\n    'message' =\u003e 'Testing message',\n    'sender' =\u003e ['text' =\u003e 'Tester'],\n    'recipients' =\u003e [\n        ['phonenr' =\u003e '+421911000000']\n    ]\n];\n$client-\u003esend($msg);\n```\n\nMail driver\n-----------\n\nI have implemented a mail driver at `Matthewbdaly\\SMS\\Drivers\\Mail`, but it's very basic and may not work with a lot of mail-to-SMS gateways out of the box. It accepts an instance of the `Matthewbdaly\\SMS\\Contracts\\Mailer` interface as the first argument, and the config array as the second.\n\nI've included the class `Matthewbdaly\\SMS\\PHPMailAdapter` in the library as a very basic implementation of the mailer interface, but it's deliberately very basic - it's just a very thin wrapper around the PHP `mail()` function. You will almost certainly want to create your own implementation for your own use case - for instance, if you're using Laravel you might create a wrapper class for the `Mail` facade.\n\nThe mail driver will nearly always be slower and less reliable than the HTTP-based ones, so if you have to integrate with a provider that doesn't yet have a driver, but does have a REST API, you're probably better off creating an API driver for it. If you do need to work with a mail-to-SMS gateway, you're quite likely to find that you need to extend `Matthewbdaly\\SMS\\Drivers\\Mail` to amend the functionality.\n\nLaravel and Lumen integration\n-------------------\n\nUsing Laravel or Lumen? You probably want to use [my integration package](https://packagist.org/packages/matthewbdaly/laravel-sms) rather than this one, since that includes a service provider, as well as the `SMS` facade and easier configuration.\n\nCreating your own driver\n------------------------\n\nIt's easy to create your own driver - just implement the `Matthewbdaly\\SMS\\Contracts\\Driver` interface. You can use whatever method is most appropriate for sending the SMS - for instance, if your provider has a mail-to-SMS gateway, you can happily use Swiftmailer or PHPMailer in your driver to send emails, or if they have a REST API you can use Guzzle.\n\nYou can pass any configuration options required in the `config` array in the constructor of the driver. Please ensure that your driver has tests using PHPSpec (see the existing drivers for examples), and that it meets the coding standard (the package includes a PHP Codesniffer configuration for that reason).\n\nIf you've created a new driver, feel free to submit a pull request and I'll consider including it.\n\nTODO\n----\n\nI have plans for a 2.0 release which include:\n\n* More drivers! If you're using an SMS provider that isn't on the list and you'd like to see support for it in this library, go ahead and create your own driver and submit a pull request for it.\n* Remove dependency on Guzzle and replace it with HTTPlug so it doesn't need a specific implementation.\n* Add a factory for resolving the drivers automatically.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthewbdaly%2Fsms-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatthewbdaly%2Fsms-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthewbdaly%2Fsms-client/lists"}