Laravel
Welcome to the ReSMS Laravel integration guide.
This guide explains how to send SMS messages easily in your Laravel applications using the ReSMS API.
Installation
Install our PHP SDK via Composer:
composer require resms/sdk
Quickstart
You can create a simple service to send SMS easily.
1. Create a new service
<?php
namespace App\Services;
use ReSMS\ReSMSClient;
class SMSService
{
protected $client;
public function __construct()
{
$this->client = new ReSMSClient([
'apiKey' => env('RESMS_API_KEY'),
]);
}
public function send(string $to, string $message)
{
return $this->client->sendSMS([
'to' => $to,
'message' => $message,
]);
}
}
2. Usage example in a controller
<?php
namespace App\Http\Controllers;
use App\Services\SMSService;
class NotificationController extends Controller
{
public function send()
{
$smsService = new SMSService();
$response = $smsService->send('+1234567890', 'Welcome to ReSMS!');
return response()->json($response);
}
}
Environment Variables
Configure your API key securely in .env
:
RESMS_API_KEY=your-api-key-here
Never expose this key in your frontend code.
Features
- Seamless integration with Laravel
- Support for Laravel service container
- Send transactional and promotional SMS
- Real-time message tracking
Error Handling
Always handle potential exceptions:
try {
$smsService->send('+1234567890', 'Test message');
} catch (\Exception $e) {
\Log::error('Failed to send SMS: ' . $e->getMessage());
}
Going Further
Need help? Contact our support team at support@resms.io
Last updated on