This library provides you with an easy way of sending SMS and receiving replies by integrating the TextMagic SMS Gateway into your PHP application.
TextMagic’s application programming interface (API) provides the communication link between your application and TextMagic’s SMS Gateway, allowing you to send and receive text messages and to check the delivery status of text messages you’ve already sent.
PHP 5.5 and later.
7.2+ PHP version is required to use Composer.
To install the bindings via Composer, add the following to composer.json
:
{
"repositories": [
{
"type": "git",
"url": "https://github.com/textmagic/textmagic-rest-php-v2.git"
}
],
"require": {
"textmagic/textmagic-rest-php-v2": "dev-master#v2.0.23575"
}
}
Then run composer install
5.5+ PHP version is required for manual installation.
Download the files and include autoload.php
:
require_once(__DIR__.'/vendor/autoload.php');
Please follow the installation instructions and execute the following PHP code:
require_once(__DIR__ . '/vendor/autoload.php');
use TextMagic\Models\SendMessageInputObject;
use TextMagic\Api\TextMagicApi;
use TextMagic\Configuration;
// put your Username and API Key from https://my.textmagic.com/online/api/rest-api/keys page.
$config = Configuration::getDefaultConfiguration()
->setUsername('YOUR_USERNAME')
->setPassword('YOUR_API_KEY');
$api = new TextMagicApi(
new GuzzleHttp\Client(),
$config
);
// Simple ping request example
try {
$result = $api->ping();
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling TextMagicApi->ping: ', $e->getMessage(), PHP_EOL;
}
// Send a new message request example
$input = new SendMessageInputObject();
$input->setText('Test message test');
$input->setPhones('+19993322111,+19993322110');
try {
$result = $api->sendMessage($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling TextMagicApi->sendMessage: ', $e->getMessage(), PHP_EOL;
}
// Get all outgoing messages request example
try {
$result = $api->getAllOutboundMessages(1, 10);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling TextMagicApi->getAllOutboundMessages: ', $e->getMessage(), PHP_EOL;
}
// Upload an avatar for a contacts list (group) example. 3223 number here it is sample list ID
try {
$file = new SplFileObject("test.jpg");
$result = $api->uploadListAvatar($file, 3223);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling TextMagicApi->uploadListAvatar: ', $e->getMessage(), PHP_EOL;
}
The library is available as open source under the terms of the MIT License.