rkingbishnoi / brevo-laravel-sdk
A Laravel package that provides an easy-to-use interface for interacting with Brevo's email, SMS, and marketing automation services, enabling seamless API integration for messaging and campaign management.
Requires
- php: ^7.4|^8.0
- getbrevo/brevo-php: ^1.0.2
Requires (Dev)
- orchestra/testbench: ^6.0
This package is not auto-updated.
Last update: 2025-06-12 14:22:58 UTC
README
A Laravel package providing an easy-to-use interface for interacting with Brevo's email, SMS, and marketing automation services. This SDK enables seamless API integration for messaging and campaign management.
📌 Features
✅ Built on the Official Brevo PHP SDK
✅ Easy Brevo API Integration
✅ Support for Email, SMS, WhatsApp, and Campaign APIs
✅ Simple Laravel Facade for Quick Usage
✅ Built-in Exception Handling & API Validation
✅ Secure API Key Configuration
📦 Installation
Step 1: Install via Composer
You can install the package via Composer:
composer require rkingbishnoi/brevo-laravel-sdk
Step 2: Publish the Configuration
Publish the package configuration file to your application: bash Copy Edit
php artisan vendor:publish --tag=config
This will create a config/brevo.php file where you can set your Brevo API key.
Step 3: Set the API Key
Add your Brevo API key in your .env file:
BREVO_API_KEY=your-brevo-api-key
🚀 Usage Guide
Once you have installed and configured the package, you can start using it in your Laravel application.
This package provides a facade (Brevo) for interacting with various Brevo API services such as Transactional Emails, SMS, Contacts, and Campaigns.
📝 Quick Cheat Sheet
Action | API Method | Example Usage 📌 |
---|---|---|
✅ Send Transactional Email | Brevo::transactionalEmailsApi()->sendTransacEmail() | 📌 View Code |
✅ Send Transactional SMS | Brevo::transactionalSmsApi()->sendTransacSms() | 📌 View Code |
✅ Fetch Account Details | Brevo::accountApi()->getAccount() | 📌 View Code |
✅ Fetch Contact Lists | Brevo::listsApi()->getLists() | 📌 View Code |
✅ Send WhatsApp Message | Brevo::transactionalWhatsAppApi()->sendWhatsAppTemplateMessage() | 📌 View Code |
📧 Sending an Email via Brevo
use Rkingbishnoi\BrevoLaravelSdk\Facades\Brevo;
try {
$emailApi = Brevo::transactionalEmailsApi();
$response = $emailApi->sendTransacEmail([
'sender' => ['name' => 'Your Company', 'email' => 'your-email@yourdomain.com'],
'to' => [['email' => 'recipient@example.com', 'name' => 'Recipient Name']],
'subject' => 'Welcome to our platform!',
'htmlContent' => '<p>Hello, thank you for signing up!</p>',
]);
return response()->json(['success' => true, 'response' => $response]);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
🔥 Error Handling
This package comes with built-in exception handling for API-related issues.
Handling Missing API Key If the API key is missing, the package will throw:
throw new MissingApiKeyException('The Brevo API key is missing. Please set the [BREVO_API_KEY] in your .env file or config/brevo.php.');```
How to Handle?
use Rkingbishnoi\BrevoLaravelSdk\Facades\Brevo;
use Rkingbishnoi\BrevoLaravelSdk\Exceptions\MissingApiKeyException;
try {
$account = Brevo::accountApi()->getAccount();
} catch (MissingApiKeyException $e) {
return response()->json(['error' => $e->getMessage()], 400);
} catch (Exception $e) {
return response()->json(['error' => 'Something went wrong.'], 500);
}
Testing To run tests, use:
vendor/bin/phpunit
If you haven't installed Orchestra Testbench, install it with:
composer require --dev orchestra/testbench
Then run :
vendor/bin/phpunit
📄 License
This package is open-source software licensed under the MIT License
.
📢 Contributing
We encourage and appreciate contributions! If you have any suggestions, improvements, or bug fixes, feel free to submit a pull request or start a discussion via issues.
📌 How to Contribute
- Fork the repository
- Create a new branch (
git checkout -b feature-branch
) - Make your changes and ensure they follow best practices
- Commit your changes (
git commit -m "Describe your changes"
) - Push to your branch (
git push origin feature-branch
) - Submit a pull request for review
🚀 Let's build something great together!