Newsletter
The newsletter subscription component is a simple, ready-to-use Livewire component that integrates with Mailchimp to collect email subscriptions.
Requirements
To use the newsletter component, ensure the following:
- Spatie Laravel Newsletter package is installed. Please refer to the Spatie Laravel Newsletter documentation for installation instructions.
-
Mailchimp API key and List ID are set in your
.envfile:NEWSLETTER_API_KEY=your-mailchimp-api-key NEWSLETTER_LIST_ID=your-mailchimp-list-id
How It Works
The component uses the Spatie Laravel Newsletter package to interface with Mailchimp's API. When a user submits their email address.
Mailchimp Setup
Before using the newsletter component, you need to set up your Mailchimp account and configure the required environment variables.
Step 1: Get Your Mailchimp API Key
- Log in to your Mailchimp account
- Navigate to Account > Extras > API keys
- If you don't have an API key, click Create A Key
- Copy the generated API key (it will look like:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-us1)
Step 2: Get Your Mailchimp List ID
- In your Mailchimp dashboard, go to Audience > More Options > Audiance Settings
- Scroll down to find your Audiance ID
- Copy the List ID (it will look like:
a1b2c3d4e5)
Note: If you don't have a list yet, create one first by going to Audience > Create Audience.
Usage
The newsletter component is a standard Livewire component that can be included anywhere in your Blade templates. Simply use the Livewire component directive:
<livewire:forms.newsletter />
References
| Category | Path / Name | Description |
|---|---|---|
| Livewire Component | App\Livewire\Forms\Newsletter | Main newsletter subscription component |
| View | resources/views/livewire/forms/newsletter.blade.php | Newsletter form template |
| Config | config/newsletter.php | Newsletter and Mailchimp configuration |
| Package | spatie/laravel-newsletter | Third-party package providing Mailchimp integration |