Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer. You can expect quick tips, links to interesting tutorials, opinions and packages. Want to learn the cool stuff? Then sign up now!

Manage newsletters in Laravel 5

A few hours ago I tagged version 1.0.0 of a my new package: laravel-newsletter. It provides a very easy way to interact with email marketing services. Or maybe I should simply say MailChimp, as it is currently the only supported supported service.

After you install the package (un)subscribing an e-mail is as easy as

Newsletter::subscribe([email protected]')
Newsletter::unsubscribe([email protected]')

There are a few more methods provided and you can also access the underlying MailChimp API.  Read all about it in the readme of the package.

I was going to add more functionality but the recent release of the new version of MailChimp’s API made me rethink my plan. As soon as there is a php wrapper available for the new version of API I’ll put some more work in the package.

Freek Van der Herten is a partner and developer at Spatie, an Antwerp based company that specializes in creating web apps with Laravel. After hours he writes about modern PHP and Laravel on this blog. When not coding he’s probably rehearsing with his kraut rock band.
  • shabith Ishan

    Hi Thanks for this great package. 🙂

    I’m new to laravel and php. Can you tell me how to subscribe a email within the controller?

    I did try to implement it in view just like in example.

    Newsletter::subscribe(‘[email protected]’);

    But it gives be below error.

    ErrorException in NewsletterList.php line 37:Trying to get property of non-object (View: /Users/shabithishan/Projects/training/project/l5/resources/views/summary/share.blade.php)

    • Maks

      You need set real API key in you env file of newsletter config file.

  • Josh @ Mightyhive

    Im getting the same as Shabith

  • Pingback: Mailchimp Laravel Package - Laravel News()

  • Hi Guys,
    I had the same issue as you.
    It is quite simple. If you have added the class and the alias in the app.php config file, you do not do the USE CLASS in the top of your controller/routes.php, but instead just reference it by the Alias set in app.php config. Eg. Newsletter::subscribe(‘[email protected]’)