spatie/laravel-newsletter
Integrate newsletter subscriptions in Laravel with a simple API. Supports Mailcoach and Mailchimp, lets you manage lists, subscribe/unsubscribe users, and configure drivers via a published config file.
Subscribed, Unsubscribed), enabling integration with Laravel’s event system or third-party services (e.g., analytics, CRM).Newsletter::subscribe()). Compatible with Laravel’s service container and queue systems.newsletter_subscriptions table), ensuring compatibility with any supported database.spatie/laravel-newsletter for breaking changes (e.g., rate limits, endpoint deprecations).queue:work) and retries for transient API failures.User → Subscription).Newsletter::shouldReceive('subscribe')->once()).composer require spatie/laravel-newsletter
php artisan vendor:publish --provider="Spatie\Newsletter\NewsletterServiceProvider"
php artisan migrate
config/newsletter.php) to set API keys, default lists, and queue connections..env for service-specific credentials (e.g., MAILCHIMP_API_KEY).User) for user-specific lists:
use Spatie\Newsletter\HasSubscriptions;
class User extends Authenticatable {
use HasSubscriptions;
}
Newsletter, Mailcoach, Mailchimp) or inject services:
$subscription = Newsletter::subscribe('user@example.com', 'list-id');
Newsletter::subscribe().Spatie\Newsletter\Webhook events.NewsletterService).Monolog channel).spatie/laravel-newsletter to leverage new features/bug fixes. Monitor changelog for breaking changes..env and check service status pages.failed_jobs table and adjust retry logic.\Log::info('Subscription attempt', ['email' => $email, 'list_id' => $listId, 'response' => $response]);
email and list_id columns in newsletter_subscriptions for large volumes.User::chunk(100, function ($users) {
foreach ($users as $user) {
Newsletter::subscribe($user->email, 'list-id');
}
});
Mailchimp::lists()) if frequently accessed.| Failure Scenario | Mitigation | Recovery |
|---|---|---|
| API Rate Limits | Implement exponential backoff in custom service classes. | Monitor API response codes; adjust queue delays. |
| Queue Worker Crashes | Use queue:failed table and queue:retry command. |
Restart workers; investigate crashes (e.g., OOM, timeouts). |
| Webhook Delivery Failures | Validate webhook signatures; retry transient failures. | Log failed webhooks; notify admins via Slack/email. |
| Database Locks | Optimize queries; avoid long transactions. | Monitor slow_query_log; adjust isolation levels. |
| Service Outage (Mailcoach/MailChimp) | Fallback to local storage for critical subscriptions. | Notify users; implement offline-first logic. |
How can I help you explore Laravel packages today?