Giter Club home page Giter Club logo

mailchimp-laravel's Introduction

skovmand/mailchimp-laravel

A minimal service provider to set up and use the Mailchimp PHP library in Laravel 5.

How it works

This package contains a service provider, which binds an instance of an initialized Mailchimp client to the IoC-container.

You recieve the Mailchimp client through depencency injection already set up with your own API key.

Usage example

class NewsletterManager 
{
	protected $mailchimp;
	protected $listId = '1234567890'        // Id of newsletter list
	
	/**
	 * Pull the Mailchimp-instance (including API-key) from the IoC-container.
	 */
	public function __construct(Mailchimp $mailchimp) 
	{
		$this->mailchimp = $mailchimp;
	}

	/**
	 * Access the mailchimp lists API
	 */
	public function addEmailToList($email) 
	{
		try {
			$this->mailchimp
				->lists
				->subscribe(
					$this->listId, 
					['email' => $email]
				);
        } catch (\Mailchimp_List_AlreadySubscribed $e) {
        	// do something
        } catch (\Mailchimp_Error $e) {
        	// do something
        }
	}
}

You can also instantiate the Mailchimp client using:

$mailchimp = App::make('Mailchimp');

Setup

Step 1: Adding the dependency to composer.json

Add this to your composer.json in your Laravel folder. Note: Adding this dependency will automatically setup "mailchimp/mailchimp": "~2.0" too.

"require": {
    ...
    "skovmand/mailchimp-laravel": "1.*",
    ...
}

Step 2: Register the service provider

Register the service provider in config/app.php by inserting into the providers array

'providers' => [
	...
	'Skovmand\Mailchimp\MailchimpServiceProvider',
	...
]

Step 3: From the command-line run

php artisan vendor:publish --provider="Skovmand\Mailchimp\MailchimpServiceProvider"

This will publish config/mailchimp.php to your config folder. In this file, insert your Mailchimp API key:

'apikey' => 'your-api-key-here',

Good to go!

mailchimp-laravel's People

Contributors

skovmand avatar

Watchers

James Cloos 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.