An unofficial PHP SDK for the Mobile Message SMS API. Send SMS messages, track delivery status, and manage your messaging campaigns with Australia's leading SMS service.
- ✅ Send single and bulk SMS messages
- ✅ Track message delivery status
- ✅ Check account balance
- ✅ Simple and Advanced API endpoints
- ✅ Comprehensive error handling
- ✅ Laravel and CodeIgniter compatible
- ✅ PSR-4 autoloading
- ✅ Extensive test coverage
- ✅ Type-safe with PHP 7.4+ support
Install the SDK via Composer:
composer require mobilemessage/php-sdk- PHP 7.4 or higher
- Guzzle HTTP client
- Mobile Message API credentials
<?php
require_once 'vendor/autoload.php';
use MobileMessage\MobileMessageClient;
use MobileMessage\DataObjects\Message;
// Initialise the client
$client = new MobileMessageClient('your_username', 'your_password');
// Send a single SMS
$response = $client->sendMessage(
'0412345678', // recipient
'Hello from Mobile Message!', // message
'YourCompany', // sender ID
'optional-reference' // custom reference (optional)
);
if ($response->isSuccess()) {
echo "Message sent! ID: " . $response->getMessageId();
} else {
echo "Failed to send: " . $response->getStatus();
}use MobileMessage\MobileMessageClient;
$client = new MobileMessageClient('your_username', 'your_password');
// Optional: Configure HTTP client options
$client = new MobileMessageClient('your_username', 'your_password', [
'timeout' => 60,
'connect_timeout' => 10,
]);$response = $client->sendMessage(
'0412345678',
'Your verification code is 1234',
'YourApp'
);
echo "Status: " . $response->getStatus() . "\n";
echo "Message ID: " . $response->getMessageId() . "\n";
echo "Cost: " . $response->getCost() . " credits\n";use MobileMessage\DataObjects\Message;
$messages = [
new Message('0412345678', 'Message 1', 'YourApp', 'ref1'),
new Message('0412345679', 'Message 2', 'YourApp', 'ref2'),
new Message('0412345680', 'Message 3', 'YourApp', 'ref3'),
];
$responses = $client->sendMessages($messages);
foreach ($responses as $response) {
echo "To: {$response->getTo()}, Status: {$response->getStatus()}\n";
}$response = $client->sendSimple(
'61412345678', // international format
'Hello World!',
'YourApp'
);$balance = $client->getBalance();
echo "Current balance: " . $balance->getBalance() . " credits\n";
echo "Plan: " . $balance->getPlan() . "\n";
if ($balance->hasCredits()) {
echo "You have credits available\n";
}// Get message status by ID
$messageId = 'your-message-id-here';
$status = $client->getMessage($messageId);
echo "Message Status: " . $status->getStatus() . "\n";
echo "Delivered: " . ($status->isDelivered() ? 'Yes' : 'No') . "\n";
echo "Failed: " . ($status->isFailed() ? 'Yes' : 'No') . "\n";
if ($status->getDeliveredAt()) {
echo "Delivered at: " . $status->getDeliveredAt() . "\n";
}use MobileMessage\DataObjects\Message;
use MobileMessage\Exceptions\ValidationException;
$message = new Message('0412345678', 'Test message', 'Sender');
try {
$client->validateMessage($message);
echo "Message is valid\n";
} catch (ValidationException $e) {
echo "Validation error: " . $e->getMessage() . "\n";
}Add to your config/app.php:
// Create a custom service provider
'providers' => [
// ... other providers
App\Providers\MobileMessageServiceProvider::class,
],<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use MobileMessage\MobileMessageClient;
class MobileMessageServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(MobileMessageClient::class, function ($app) {
return new MobileMessageClient(
config('services.mobile_message.username'),
config('services.mobile_message.password')
);
});
}
}Add to your config/services.php:
'mobile_message' => [
'username' => env('MOBILE_MESSAGE_USERNAME'),
'password' => env('MOBILE_MESSAGE_PASSWORD'),
],<?php
namespace App\Http\Controllers;
use MobileMessage\MobileMessageClient;
class SmsController extends Controller
{
public function __construct(private MobileMessageClient $smsClient)
{
}
public function sendNotification(Request $request)
{
$response = $this->smsClient->sendMessage(
$request->phone,
$request->message,
'YourApp'
);
return response()->json([
'success' => $response->isSuccess(),
'message_id' => $response->getMessageId(),
]);
}
}Create application/libraries/MobileMessage.php:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . '../vendor/autoload.php';
use MobileMessage\MobileMessageClient;
class MobileMessage
{
private $client;
public function __construct($params = [])
{
$CI = &get_instance();
$CI->load->config('mobile_message');
$this->client = new MobileMessageClient(
$CI->config->item('mobile_message_username'),
$CI->config->item('mobile_message_password')
);
}
public function send_sms($to, $message, $sender, $custom_ref = null)
{
return $this->client->sendMessage($to, $message, $sender, $custom_ref);
}
public function get_balance()
{
return $this->client->getBalance();
}
}Create application/config/mobile_message.php:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$config['mobile_message_username'] = 'your_username';
$config['mobile_message_password'] = 'your_password';<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Sms extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('mobilemessage');
}
public function send_notification()
{
$response = $this->mobilemessage->send_sms(
'0412345678',
'Your order has been confirmed!',
'YourStore'
);
if ($response->isSuccess()) {
echo "SMS sent successfully!";
} else {
echo "Failed to send SMS: " . $response->getStatus();
}
}
}The SDK provides specific exception types for different error conditions:
use MobileMessage\Exceptions\AuthenticationException;
use MobileMessage\Exceptions\ValidationException;
use MobileMessage\Exceptions\RateLimitException;
use MobileMessage\Exceptions\MobileMessageException;
try {
$response = $client->sendMessage('0412345678', 'Test', 'Sender');
} catch (AuthenticationException $e) {
echo "Authentication failed: " . $e->getMessage();
} catch (ValidationException $e) {
echo "Validation error: " . $e->getMessage();
} catch (RateLimitException $e) {
echo "Rate limit exceeded: " . $e->getMessage();
} catch (MobileMessageException $e) {
echo "API error: " . $e->getMessage();
}For easy testing with your real Mobile Message API credentials:
# Run the interactive setup script
./setup-testing.shThis will:
- Create a
.envfile with your API credentials - Configure test phone number and sender ID
- Set up safety controls for real SMS testing
-
Copy the environment template:
cp .env.example .env
-
Edit
.envwith your credentials:API_USERNAME=your_api_username API_PASSWORD=your_api_password TEST_PHONE_NUMBER=0400322583 SENDER_PHONE_NUMBER=your_sender_phone ENABLE_REAL_SMS_TESTS=false # Set to true to send real SMS ENABLE_BULK_SMS_TESTS=false # Set to true to enable bulk testing
# Unit tests only (safe, no API calls)
composer test
# Integration tests (requires valid .env credentials)
composer test -- --testsuite Integration
# Test coverage report
composer test-coverage
# Comprehensive test script with real API
php examples/test_example.php
# Test individual examples
php examples/basic_example.php
php examples/bulk_example.phpENABLE_REAL_SMS_TESTS=true will send actual SMS messages and use credits from your Mobile Message account.
See the examples/ directory for complete working examples:
| Method | Description | Parameters | Returns |
|---|---|---|---|
sendMessage() |
Send a single SMS | $to, $message, $sender, $customRef? |
MessageResponse |
sendMessages() |
Send multiple SMS | Message[] |
MessageResponse[] |
sendSimple() |
Send via simple API | $to, $message, $sender, $customRef? |
MessageResponse |
getMessage() |
Get message status | $messageId |
MessageStatusResponse |
getBalance() |
Get account balance | - | BalanceResponse |
validateMessage() |
Validate message | Message |
void (throws on error) |
- Message: Input message data
- MessageResponse: API response for sent messages
- MessageStatusResponse: Message status lookup response
- BalanceResponse: Account balance information
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This is an unofficial SDK for the Mobile Message API. It is not affiliated with or endorsed by Mobile Message Pty Ltd. For official support and documentation, please visit Mobile Message.