Run composer req revision-ten/mailchimp
.
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],
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.
Use the MailchimpService to subscribe users.
Symfony 3.4.* example:
$mailchimpService = $this->container->get(MailchimpService::class);
$subscribed = $mailchimpService->subscribe('dailyNewsletterCampagin', '[email protected]', 'My Website', [
'FNAME' => 'John',
'LNAME' => 'Doe',
]);
Or unsubscribe users:
$mailchimpService = $this->container->get(MailchimpService::class);
$unsubscribed = $mailchimpService->unsubscribe('dailyNewsletterCampagin', '[email protected]');