Git Product home page Git Product logo

laravel-newsletter's Introduction

Manage newsletters in Laravel 5

Latest Version Software License Build Status SensioLabsInsight Quality Score Total Downloads

This package provides an easy way to integrate email marketing services with Laravel 5. Currently the package only supports MailChimp. In the future more services may get added.

Spatie is webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Installation

You can install this package via composer using:

composer require spatie/laravel-newsletter

You must also install this service provider.

// config/app.php
'providers' => [
    ...
    'Spatie\Newsletter\NewsletterServiceProvider',
    ...
];

If you want to make use of the facade you must install it as well.

// config/app.php
'aliases' => [
    ...
    'Newsletter' => 'Spatie\Newsletter\NewsletterFacade',
];

To publish the config file to app/config/laravel-newsletter.php run:

php artisan vendor:publish --provider="Spatie\Newsletter\NewsletterServiceProvider"

This wil publish a file laravel-newsletter.php in your config directory with the following contents:

return [

    'mailChimp' => [

        /*
         * The api key of a MailChimp account. You can find yours here:
         * https://us10.admin.mailchimp.com/account/api-key-popup/
         */
        'apiKey' => env('MAILCHIMP_APIKEY'),

        /*
         * Here you can define properties of the lists you want to
         * send campaigns.
         */
        'lists' => [

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

                /*
                 * A mail chimp list id. Check the mailchimp docs if you don't know
                 * how to get this value:
                 * http://kb.mailchimp.com/lists/managing-subscribers/find-your-list-id
                 */
                'id' => '',

                /*
                 * These values will be used when creating a new campaign.
                 */
                'createCampaign' => [
                    'fromEmail' => '',
                    'fromName' => '',
                    'toName' => ''
                ],
                
                /*
                 * These values will be used when subscribing to a list.
                 */
                'subscribe' => [
                    'emailType' => 'html',
                    'requireDoubleOptin' => false,
                    'updateExistingUser' => false
                ],
                
                /*
                 * These values will be used when unsubscribing from a list.
                 */
                'unsubscribe' => [
                    'deletePermanently' => false,
                    'sendGoodbyeEmail' => false,
                    'sendUnsubscribeEmail' => false
                ],
            ],
        ],
    ],
];

Upgrading

From 1.0 to 2.0

If you specified a listName on a subscription you need to modify that call from Newsletter::subscribe($email, $listName) to Newsletter::subscribe($email, [], $listName)

Usage

After you've installed the package and filled in the values in the config-file working with this package will be a breeze.

Subscribing an email address can be done like this:

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

Let's unsubcribe someone:

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

You can pass some merge variables as the second argument:

Newsletter::subscribe('[email protected]', ['firstName'=>'Rince', 'lastName'=>'Wind']);

This is how you create a campaign:

$subject = 'The Truth newsletter';
$contents = '<h1>Big news</h1>The world is carried by four elephants on a turtle!';

Newsletter::createCampaign($subject, $contents);

The method will create a campaign, but not send it.

If you have multiple lists defined in the config file you must pass the name of the list an extra parameter:

Newsletter::subscribe('[email protected]', ['firstName'=>'Havelock', 'lastName'=>'Vetinari'], 'mySecondList');
Newsletter::unsubscribe('[email protected]', ['firstName'=>'Sam', 'lastName'=>'Vines'], 'mySecondList');

Newsletter::createCampaign($subject, $contents, 'mySecondList);

If you need more functionality you get an instance of the underlying service api with:

$api = Newsletter::getApi();

As this package currently only supports MailChimp this method will always return an instance of the MailChimp API.

Testing

Run the tests with:

vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

This package was inspired by the Bulk Email Notifications series on Laracasts.

About Spatie

Spatie is webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

License

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

laravel-newsletter's People

Contributors

drbyte avatar freekmurze avatar pixelpeter avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.