revision-ten/mailchimp

A very minimal Mailchimp integration for Symfony

1.0.0 2021-08-16 14:26 UTC

This package is auto-updated.

Last update: 2024-11-10 17:47:35 UTC


README

Installation

Install via composer

Run composer req revision-ten/mailchimp.

Add the Bundle

Add the bundle to your AppKernel (Symfony 3.4.*) or your Bundles.php (Symfony 4.*).

Symfony 3.4.* /app/AppKernel.php:

new \RevisionTen\Mailchimp\MailchimpBundle(),

Symfony 4.* /config/bundles.php:

RevisionTen\Mailchimp\MailchimpBundle::class => ['all' => true],

Configuration

Configure the bundle:

# Mailchimp example config.
mailchimp:
    api_key: 'XXXXXXXXXXXXXXXXXXXXXXX-us5' # Your mailchimp api key.
    campaigns:
        dailyNewsletterCampagin:
            list_id: '123456' # Id of your newsletter list.

Usage

Use the MailchimpService to subscribe users.

Symfony 3.4.* example:

$mailchimpService = $this->container->get(MailchimpService::class);

$subscribed = $mailchimpService->subscribe('dailyNewsletterCampagin', 'visitor.email@domain.tld', 'My Website', [
    'FNAME' => 'John',
    'LNAME' => 'Doe',
]);

Or unsubscribe users:

$mailchimpService = $this->container->get(MailchimpService::class);

$unsubscribed = $mailchimpService->unsubscribe('dailyNewsletterCampagin', 'visitor.email@domain.tld');