Sends text messages to a provider specified.
The default driver is set to Twilio which will expand eventually to pull in other service providers.
Pull in the composer package by running the command below:
composer require oliveris/text
Import the Text namespace into the class (autoloading)
use Text\Text;
If the env method is available from your application you can set the env variables, see example below:
// TWILIO SPECIFIC SETTINGS
TWILIO_SID={sid_from_twilio}
TWILIO_TOKEN={token_from_twilio}
// may want to set the inbound number
TWILIO_INBOUND_NUMBER={number_that_captures_inbound_sms}
If the env method is not available, see example below to set them using an alternate method:
$text = Text::getDriver("twilio");
$text->setSid(***********);
$text->setToken(************);
// may want to set the inbound number
$text->setInboundNumber(************);
The following example shows how you can send a simple SMS
$text = Text::getDriver("twilio");
$text->setBody('Lorem ipsum dolor sit amet, mnesarchum interpretaris vis eu.');
$text->setTo('+447*********');
$text->setFrom(env('TWILIO_NUMBER'));
$text->send();
The following example shows how you can can send a simple MMS
Noticed how this may display differently dependent on device. (iphone/android)
$text = Text::getDriver("twilio");
$text->setBody('Lorem ipsum dolor sit amet, mnesarchum interpretaris vis eu.');
$text->setMedia('url_to_media');
$text->setTo('+447*********');
$text->setFrom(env('TWILIO_NUMBER'));
$text->send();
To get all of the inbound texts sent to the number
$text = Text::getDriver("twilio");
$text->setBody('Lorem ipsum dolor sit amet, mnesarchum interpretaris vis eu.');
$text->setTo('+447*********');
$text->setFrom(env('TWILIO_NUMBER'));
$text->send();
- PHP 7
We use Semantic Versioning 1.0.0, for example v1.0.0.
- Sam Oliveri - Software Engineer
Text is open-sourced software licensed under the MIT license.