2017 © Pedro Peláez
 

library laravel-newsletter

Manage newsletters in Laravel

image

spatie/laravel-newsletter

Manage newsletters in Laravel

  • Monday, July 9, 2018
  • by Spatie
  • Repository
  • 33 Watchers
  • 765 Stars
  • 451,182 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 116 Forks
  • 4 Open issues
  • 39 Versions
  • 13 % Grown

The README.md

Manage newsletters in Laravel

Latest Version MIT Licensed run-tests PHPStan Total Downloads, (*1)

This package provides an easy way to integrate subscriptions to email lists of various email services., (*2)

Currently this package support:, (*3)

Support us

, (*4)

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products., (*5)

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall., (*6)

Installation

You can install this package via Composer using:, (*7)

composer require spatie/laravel-newsletter

To publish the config file to config/newsletter.php run:, (*8)

php artisan vendor:publish --tag="newsletter-config"

This will publish a file newsletter.php in your config directory with the following contents:, (*9)

return [

    /*
     * The driver to use to interact with MailChimp API.
     * You may use "log" or "null" to prevent calling the
     * API directly from your environment.
     */
    'driver' => env('NEWSLETTER_DRIVER', Spatie\Newsletter\Drivers\MailcoachDriver::class),

    /**
     * These arguments will be given to the driver.
     */
    'driver_arguments' => [
        'api_key' => env('NEWSLETTER_API_KEY'),

        'endpoint' => env('NEWSLETTER_ENDPOINT'),
    ],

    /*
     * The list name to use when no list name is specified in a method.
     */
    'default_list_name' => 'subscribers',

    'lists' => [

        /*
         * This key is used to identify this list. It can be used
         * as the listName parameter provided in the various methods.
         *
         * You can set it to any string you want and you can add
         * as many lists as you want.
         */
        'subscribers' => [

            /*
             * When using the Mailcoach driver, this should be the Email list UUID
             * which is displayed in the Mailcoach UI
             *
             * When using the MailChimp driver, this should be a MailChimp list id.
             * http://kb.mailchimp.com/lists/managing-subscribers/find-your-list-id.
             */
            'id' => env('NEWSLETTER_LIST_ID'),
        ],
    ],
];

Using Mailcoach

To let this package work with Mailcoach, you need to install the Mailcoach SDK., (*10)

composer require spatie/mailcoach-sdk-php

Next, you must provide values for the API key, endpoint and list.subscribers.id in the config file. You'll find the API key and endpoint in the Mailcoach settings screen. The value for list.subscribers.id must be the UUID of an email list on Mailcoach. You'll find this value on the settings screen of an email list, (*11)

Using MailChimp

To use MailChimp, install this extra package., (*12)

composer require drewm/mailchimp-api

The driver key of the newsletter config file must be set to Spatie\Newsletter\Drivers\MailChimpDriver::class., (*13)

Next, you must provide values for the API key and list.subscribers.id. You'll find these values in the MailChimp UI., (*14)

The endpoint config value must be set to null., (*15)

Usage

After you've installed the package and filled in the values in the config-file working with this package will be a breeze. All the following examples use the facade. Don't forget to import it at the top of your file., (*16)

use Spatie\Newsletter\Facades\Newsletter;

Subscribing, updating and unsubscribing

Subscribing an email address can be done like this:, (*17)

use Newsletter;

Newsletter::subscribe('rincewind@discworld.com');

Let's unsubscribe someone:, (*18)

Newsletter::unsubscribe('the.luggage@discworld.com');

For Mailcoach, you can pass extra attributes as the second argument:, (*19)

Newsletter::subscribe('rincewind@discworld.com', ['first_name' => 'Rince', 'last_name' => 'Wind']);

For MailChimp you can pass merge variables as the second argument:, (*20)

Newsletter::subscribe('rincewind@discworld.com', ['FNAME'=>'Rince', 'LNAME'=>'Wind']);

You can subscribe someone to a specific list by passing a list name:, (*21)

Newsletter::subscribe('rincewind@discworld.com', listName: 'subscribers');

That third argument is the name of a list you configured in the config file., (*22)

You can also subscribe and/or update someone. The person will be subscribed or updated if he/she is already subscribed:, (*23)

php Newsletter::subscribeOrUpdate('rincewind@discworld.com', ['first_name' => 'Rince', 'last_name' => 'Wind']);, (*24)

For MailChimp, You can subscribe someone to one or more specific group(s)/interest(s) by using the fourth argument:, (*25)

Newsletter::subscribeOrUpdate(
   'rincewind@dscworld.com', 
   ['FNAME'=>'Rince','LNAME'=>'Wind'], 
   'subscribers', 
   ['interests'=>['interestId'=>true, 'interestId'=>true]],
);

Simply add false if you want to remove someone from a group/interest., (*26)

Here's how to unsubscribe someone from a specific list:, (*27)

Newsletter::unsubscribe('rincewind@discworld.com', 'subscribers');

Deleting subscribers

Deleting is not the same as unsubscribing. Unlike unsubscribing, deleting a member will result in the loss of all history (add/opt-in/edits) as well as removing them from the list. In most cases, you want to use unsubscribe instead of delete., (*28)

Here's how to perform a delete:, (*29)

Newsletter::delete('rincewind@discworld.com');

Getting subscriber info

You can get information on a subscriber by using the getMember function:, (*30)

Newsletter::getMember('lord.vetinari@discworld.com');

For MailCoach, this will return an instance of Spatie\Mailcoach\Resources|Subscriber For MailChimp, this will return an array with information on the subscriber., (*31)

If there's no one subscribed with that e-mail address the function will return false, (*32)

There's also a convenient method to check if someone is already subscribed:, (*33)

Newsletter::hasMember('nanny.ogg@discworld.com'); //returns a boolean

In addition to this, you can also check if a user is subscribed to your list:, (*34)

Newsletter::isSubscribed('lord.vetinari@discworld.com'); //returns a boolean

Need something else?

If you need more functionality you get an instance of the underlying API with, (*35)

$api = Newsletter::getApi();

If you're having trouble getting the MailChimp integration, you can see the last error with:, (*36)

Newsletter::getApi()->getLastError();

Testing

Run the tests with:, (*37)

vendor/bin/pest

Changelog

Please see CHANGELOG for more information on what has changed recently., (*38)

Contributing

Please see CONTRIBUTING for details., (*39)

Security

If you discover any security-related issues, please email security@spatie.be instead of using the issue tracker., (*40)

Credits

License

The MIT License (MIT). Please see License File for more information., (*41)

The Versions

09/07 2018

dev-master

9999999-dev https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

10/03 2018

4.2.1

4.2.1.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

10/03 2018

dev-analysis-XZmow0

dev-analysis-XZmow0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

08/02 2018

4.2.0

4.2.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

08/02 2018

dev-analysis-zYZrWG

dev-analysis-zYZrWG https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

08/02 2018

dev-analysis-XapDLW

dev-analysis-XapDLW https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

08/02 2018

dev-laravel-56

dev-laravel-56 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

08/02 2018

dev-analysis-qrM4JQ

dev-analysis-qrM4JQ https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

09/11 2017

dev-analysis-qJNvYD

dev-analysis-qJNvYD https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

31/08 2017

4.1.0

4.1.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

30/08 2017

4.0.0

4.0.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

12/07 2017

3.7.0

3.7.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

11/07 2017

3.6.1

3.6.1.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

29/06 2017

3.6.0

3.6.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

23/06 2017

3.5.0

3.5.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

23/01 2017

3.4.0

3.4.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

28/11 2016

dev-analysis-XVjlbD

dev-analysis-XVjlbD https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

24/11 2016

3.3.0

3.3.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

08/11 2016

3.2.0

3.2.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

08/11 2016

dev-analysis-zDMNr5

dev-analysis-zDMNr5 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

17/10 2016

3.1.0

3.1.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

13/10 2016

3.0.6

3.0.6.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

20/09 2016

3.0.5

3.0.5.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

24/08 2016

3.0.4

3.0.4.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

24/08 2016

dev-analysis-zOLmER

dev-analysis-zOLmER https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

11/07 2016

3.0.3

3.0.3.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

22/04 2016

3.0.2

3.0.2.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

22/04 2016

3.0.1

3.0.1.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

22/04 2016

3.0.0

3.0.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

21/12 2015

2.2.0

2.2.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

15/12 2015

2.1.0

2.1.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

24/06 2015

2.0.0

2.0.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

06/06 2015

1.1.0

1.1.0.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

22/05 2015

1.0.4

1.0.4.0 https://github.com/spatie/laravel-newsletter

Manage newsletters in Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel newsletter mailchimp

08/05 2015
08/05 2015
08/05 2015
07/05 2015
07/05 2015