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](https://www.addwebsolution.com/app/uploads/2024/03/img_1.png)
Install Package for MailChimp Newsletter:
We will install the spatie/laravel-newsletter package for use of MailChimp API methods. So first you can run the below command in your cmd.
![command in your cmd.](https://www.addwebsolution.com/app/uploads/2024/03/img_2.png)
After install MailChimp Newsletter package we need to add below provider path and alias path in config/app.php.
![config/app.php.](https://www.addwebsolution.com/app/uploads/2024/03/img_3.png)
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:
![laravel-newsletter.php run in your cmd:](https://www.addwebsolution.com/app/uploads/2024/03/img_4.png)
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 :
![env variable and list](https://www.addwebsolution.com/app/uploads/2024/03/img_5.png)
Usage:
After installing the package and fill in the values in the
![config-file working with this package.](https://www.addwebsolution.com/app/uploads/2024/03/img_6.png)
Subscribing, unsubscribing and delete subscriber
![](https://www.addwebsolution.com/app/uploads/2024/03/img_7.png)
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
![](https://www.addwebsolution.com/app/uploads/2024/03/img_8-1024x197.png)