Introduction:
- Laravel Newsletter integrates with MailChimp API.
- MailChimp provides manage subscribers, send emails using campaign and also track email results etc.
- Through MailChimp, you can track how many subscribers in your list account open an email and read.
- I use spatie/laravel-newsletter for mailchimp-newsletter.
Create MailChimp Account Setting:
- If you don’t have Mailchimp account then create it from MailChimp.
- Create a list in your MailChimp account. Then click on the created list and go to settings -> List name and defaults and copy and get your ListID.
- Then get the MailChimp API Key from API Key.
Setup .env configuration:
Add your MailChimp API Key and LIst ID in .env file
Install Package for MailChimp Newsletter:
We will install spatie/laravel-newsletter package for use MailChimp API methods. So first you can run below command in your cmd.
After install MailChimp Newsletter package we need to add below provider path and alias path in config/app.php.
We need to create laravel-newsletter.php for setup MailChimp Newsletter variables.
To publish the config file to app/config/laravel-newsletter.php run in your cmd:
This will publish a file laravel-newsletter.php in your config directory with the following contents and set your mailchimp apikey .env variable and list :
Usage:
After installing the package and fill in the values in the config-file working with this package.
Subscribing, unsubscribing and delete subscriber
You can also pass some merge variables as the second argument, third argument as list name and you can also subscribe update someone:
Hope this helps you well, feel free to add your comments/feedbacks and need more assistance regarding laravel service or Hire Laravel Developer, be in touch