kowap/laravel-sendpulse
Laravel package integrating SendPulse services, providing an easy way to send emails and manage SendPulse API interactions from your Laravel app with simple configuration and a clean wrapper around the SendPulse client.
Installation
composer require kowap/laravel-sendpulse
Publish the config file:
php artisan vendor:publish --provider="Kowap\SendPulse\SendPulseServiceProvider"
Configuration
Edit .env with your SendPulse API key:
SENDPULSE_API_KEY=your_api_key_here
First Use Case: Sending an Email
Use the SendPulseMailer facade or inject the service into a controller:
use Kowap\SendPulse\Facades\SendPulseMailer;
SendPulseMailer::send([
'to' => ['email@example.com'],
'subject' => 'Test Email',
'html' => '<h1>Hello from SendPulse!</h1>',
]);
Where to Look First
Kowap\SendPulse\SendPulseServiceProvider for binding details.Kowap\SendPulse\Facades\SendPulseMailer for quick usage.config/sendpulse.php for customization.Sending Emails Use the facade or service directly:
SendPulseMailer::send([
'to' => ['user@example.com', 'admin@example.com'],
'subject' => 'Welcome',
'html' => '<p>Welcome to our platform!</p>',
'text' => 'Welcome to our platform!',
]);
Sending SMS
SendPulseMailer::sms([
'to' => '+1234567890',
'text' => 'Your verification code is 123456.',
]);
Sending Push Notifications
SendPulseMailer::push([
'to' => ['device_token_1', 'device_token_2'],
'title' => 'New Message',
'message' => 'You have a new notification.',
]);
Integrating with Laravel Mail
Override the default mailer in config/mail.php:
'driver' => 'sendpulse',
Customizing Templates Use SendPulse’s template IDs for pre-designed emails:
SendPulseMailer::send([
'to' => ['user@example.com'],
'template_id' => 12345, // Your SendPulse template ID
'variables' => ['name' => 'John'],
]);
Handling Responses Capture SendPulse’s response for logging or retries:
$response = SendPulseMailer::send([...]);
if ($response->success) {
// Handle success
}
Queueing Messages Use Laravel’s queue system for async sending:
SendPulseMailer::later(now()->addMinutes(5), [
'to' => ['user@example.com'],
'subject' => 'Delayed Email',
'html' => '<p>This email was delayed.</p>',
]);
Event Listeners
Trigger SendPulse actions on Laravel events (e.g., registered):
public function handle(Registered $event)
{
SendPulseMailer::send([
'to' => [$event->user->email],
'subject' => 'Account Created',
'html' => 'Welcome!',
]);
}
API Key Validation
SENDPULSE_API_KEY is correctly set in .env. Missing or invalid keys will throw exceptions.SENDPULSE_API_KEY=dummy_key_123
Rate Limits
429 Too Many Requests errors.Template IDs
404).Character Limits
Webhook Delays
Enable Logging
Add this to config/sendpulse.php to log all requests:
'log' => true,
Check storage/logs/laravel.log for details.
Inspect Responses
Use dd() or Log::debug() to inspect raw responses:
$response = SendPulseMailer::send([...]);
Log::debug('SendPulse Response:', $response->toArray());
Testing Locally Use a mock API key or a local SendPulse sandbox environment to test without real sends.
Custom HTTP Client Override the default Guzzle client in the service provider:
$this->app->singleton('sendpulse.http_client', function () {
return new \GuzzleHttp\Client(['timeout' => 30]);
});
Event Dispatching Extend the package to dispatch Laravel events after sends:
// In a service provider or trait
SendPulseMailer::afterSend(function ($response) {
event(new SendPulseSent($response));
});
Batch Processing
Use Laravel’s chunk() to process large lists of recipients:
User::chunk(100, function ($users) {
$emails = $users->pluck('email')->toArray();
SendPulseMailer::send(['to' => $emails, 'subject' => 'Batch Email']);
});
Fallback Mailers Combine with Laravel’s default mailer for fallback:
try {
SendPulseMailer::send([...]);
} catch (\Exception $e) {
Mail::raw('Fallback email content', function ($message) {
$message->to('user@example.com')->subject('Fallback Email');
});
}
Default From Address
SendPulse ignores the from field in emails. Use SendPulse’s configured default sender or set it via their dashboard.
Unicode Support Ensure SMS/text content uses UTF-8 encoding to avoid garbled characters in some regions.
Time Zones SendPulse uses UTC for scheduled messages. Convert Laravel’s timestamps to UTC before scheduling:
SendPulseMailer::later(now()->timezone('UTC')->addHours(1), [...]);
How can I help you explore Laravel packages today?