- How do I install spatie/laravel-newsletter in a Laravel app?
- Run composer require spatie/laravel-newsletter, then publish the config with php artisan vendor:publish --tag="newsletter-config" to create config/newsletter.php. The service provider is registered automatically via Laravel package discovery, so there is no manual provider wiring. You then set the driver and credentials through environment variables and install the provider SDK for the driver you choose (spatie/mailcoach-sdk-php, drewm/mailchimp-api, or mailerlite/mailerlite-php). There are no migrations or database tables to run, since subscribers live at the provider.
- Which email marketing providers does this Laravel newsletter package support?
- It currently ships drivers for Mailcoach, MailChimp, and MailerLite, plus a NullDriver and log drivers intended for non-production environments. You select one through the driver setting in config/newsletter.php, and the Newsletter facade delegates to the matching driver class. Because the vendor SDK is only required for the driver you actually use, you do not pull in all three dependencies.
- How do I configure credentials and multiple newsletter lists?
- Everything lives in the single publishable config/newsletter.php file: driver selection, API credentials, and a named map of list identifiers. Keep secrets in .env and reference them from the config so credentials never land in version control. You can define several named lists and pass the list name when subscribing, which makes it easy to route signups from different forms to different audiences.
- How do I subscribe and unsubscribe a user with the Newsletter facade?
- The facade exposes subscribe, subscribeOrUpdate, subscribePending, unsubscribe, delete, getMember, hasMember, and isSubscribed, along with tag-related methods. A typical call looks like Newsletter::subscribe($email, ['first_name' => 'Jane'], 'listName'), where the attribute keys depend on the active provider. Use unsubscribe to opt a user out while keeping provider history, and reserve delete for GDPR erasure requests since it destroys that history.
- Why do newsletter calls return false instead of throwing exceptions?
- The package is deliberately forgiving: driver methods generally return false on failure rather than throwing, and MailChimp only exposes the underlying error through getApi()->getLastError(). That means you should wrap every call, assert the boolean result, and throw your own domain exception or fire an alert when it is false. If you treat a false return as success you will silently lose subscribers.
- Does the package handle unsubscribes, bounces, and complaints that happen at the provider?
- No, the package is effectively write-only and synchronous, with no webhook ingestion. Unsubscribes, bounces, and spam complaints that originate inside Mailcoach, MailChimp, or MailerLite will not propagate back into your application on their own. If you need to honour withdrawal of consent reliably, add your own webhook endpoint or a scheduled reconciliation job that checks getMember, isSubscribed, or hasMember. Treat this as a compliance requirement rather than an optional nice-to-have.
- Does it support queues, retries, or rate limiting for newsletter API calls?
- Not built in. Every subscribe or unsubscribe call is a blocking HTTP request against the provider API, subject to that provider's rate limits. In production you should dispatch these calls from queued jobs, add RateLimiter and retry-with-backoff, and make the operations idempotent so a retried job does not double-subscribe a user. Also verify behaviour under Octane or long-lived workers, since the package tracks last-action state internally.
- How do I test a Laravel app that uses spatie/laravel-newsletter?
- Use the NullDriver or log drivers in your testing and local environments so no real HTTP calls leave the suite. Override newsletter.driver in phpunit.xml or in a test service provider, and assert against your own wrapper service rather than the facade directly. For integration tests against a real sandbox list, keep them in a separate suite and never run them against production credentials.
- Can I switch from MailChimp to Mailcoach or MailerLite just by changing the config?
- Only partly. The drivers are uniform at the method level, not the semantic level: subscriber attributes are first_name for Mailcoach, FNAME for MailChimp, and name for MailerLite, and getMember returns a Subscriber resource for Mailcoach but a plain array for MailChimp. MailChimp-only concepts such as groups and interests have no cross-driver equivalent. The package gives you API uniformity, not true portability, so plan a provider migration as a project rather than a config flip.
- Is spatie/laravel-newsletter actively maintained, and what are the alternatives?
- It is an MIT-licensed Spatie package with an active release history, CI test runs, and PHPStan checks; check composer.json and the GitHub releases for the exact PHP and Laravel versions supported by your release. If you only ever use one provider, calling that provider's SDK directly removes a layer, and if you need webhooks, batching, or genuine provider portability you should wrap this package behind your own SubscriptionService interface or build the integration yourself. The getApi() escape hatch lets you reach the underlying SDK when the facade lacks a feature you need.