PHPackages                             betacie/mailchimp-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. betacie/mailchimp-bundle

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

betacie/mailchimp-bundle
========================

MailChimp API Symfony Bundle

0.1.0(10y ago)13.8k[1 issues](https://github.com/gonetcats/mailchimp-bundle/issues)MITPHP

Since Sep 25Pushed 10y ago3 watchersCompare

[ Source](https://github.com/gonetcats/mailchimp-bundle)[ Packagist](https://packagist.org/packages/betacie/mailchimp-bundle)[ RSS](/packages/betacie-mailchimp-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

[![Build Status](https://camo.githubusercontent.com/324ef13c527e9d745b37819fd21a7586fa2ea8c70955d99849c70430530b3624/68747470733a2f2f7472617669732d63692e6f72672f626574616369652f6d61696c6368696d702d62756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/betacie/mailchimp-bundle)

mailchimp-bundle
================

[](#mailchimp-bundle)

This bundle will help you synchronise your project's newsletter subscribers into MailChimp.

You can [synchronize all your subscribers at once with a Symfony command](#full-synchronization-with-command) : new users will be added to MailChimp, existing users will be updated and user no longer in your project will be deleted from MailChimp.

You can also [synchronize subscribe / unsubscribe one at a time with events](#unit-synchronization-with-events).

Optionnaly, it also help you to [synchronize your list merge tags](#synchronize-merge-tags).

- [Setup](#setup)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Synchronize merge tags](#synchronize-merge-tags)
    - [Full synchronization with command](#full-synchronization-with-command)
    - [Unit synchronization with events](#unit-synchronization-with-events)

Setup
-----

[](#setup)

Add bundle to your project:

```
composer require betacie/mailchimp-bundle
```

Add `Betacie\MailChimpBundle\BetacieMailChimpBundle` to your `AppKernel.php`:

```
$bundles = [
    // ...
    new Betacie\MailChimpBundle\BetacieMailChimpBundle(),
];
```

Configuration
-------------

[](#configuration)

You need to add the list in MailChimp's backend first.

For each list you must define a configuration in your `config.yml`:

```
betacie_mailchimp:
    api_key: YOURMAILCHIMPAPIKEY
    lists:
        list1:
            # optional language option, used only in full synchronization
            mc_language: 'fr'

            # optional merge tags you want to synchronize
            merge_tags:
                -
                    tag: FIRSTTAG
                    name: My first tag
                    options: {"field_type":"radio", "choices": ["foo", "bar"]}
                -
                    tag: SECONDTAG
                    name: My second tag

            # provider used in full synchronization
            subscriber_providers: 'yourapp.provider1'

        list2:
            subscriber_providers: 'yourapp.provider2'
```

Where `listX` is the name of your MailChimp lists, and `yourapp.providerX` is the key of your provider's service that will provide the subscribers that need to be synchronized in MailChimp. The key `mc_language` is optional and will set this language for all subscribers in this list, see [the list of accepted language codes](http://kb.mailchimp.com/lists/managing-subscribers/view-and-edit-subscriber-languages#code).

Defining lists and providers is necessary only if you use full synchronization with the command.

Usage
-----

[](#usage)

### Synchronize merge tags

[](#synchronize-merge-tags)

Merge tags (or merge vars) are values you can add to your subscribers (for example the firstsname or birthdate of your user). You can then use these tags in your newsletters or create segments out of them.

To learn more about merge tags, please see this [guide on MailChimp](http://kb.mailchimp.com/merge-tags/using/getting-started-with-merge-tags).

To synchronize you need to create your lists in MailChimp backend first. Then you need to add them in your `config.yml` as shown in the [above configuration](#configuration). The `options` you can provide are the same as the one found in [MailChimp API](https://apidocs.mailchimp.com/api/2.0/lists/merge-var-add.php).

You can then synchronize the tags using the `app/console betacie:mailchimp:synchronize-merge-tags` command. Note that every tag that are present in MailChimp but are not defined in your configuration **will be deleted along with associated values**.

### Full synchronization with command

[](#full-synchronization-with-command)

You can synchronize all subscribers of your project at once by calling the Symfony command `app/console betacie:mailchimp:synchronize-subscribers`. It will first fetch all the subscribers already present in MailChimp and unsubscribe any subscribers that are not in your projet (they might have been deleted on the project side), it will then send all your subscribers to MailChimp, new subscribers will be added and existing subscribers will be updated.

After [configuring your lists](#configuration) in `config.yml`, you need to create at least one `Provider`that will be used by the Symfony command. Your provider should be accessible via a service key (the same you reference in `subscriber_providers` in the configuration above):

```
services:
    yourapp_mailchimp_subscriber_provider:
        class: YourApp\App\Newsletter\SubscriberProvider
        arguments: [@yourapp_user_repository]
```

It should implement `Betacie\MailChimpBundle\Provider\ProviderInterface` and return an array of `Betacie\MailChimpBundle\Subscriber\Subscriber` objects. The first argument of the `Subscriber` object is its e-mail, the second argument is an array of merge tags values you need to add in MailChimp's backend in your list settings under `List fields and *|MERGE|* tags` (see this [guide on MailChimp](http://kb.mailchimp.com/merge-tags/using/getting-started-with-merge-tags) to add merge tags in your list).

```
