in Uncategorized

Create and send mailchimp campaign with mlpz/mailchimp-bundle

The mlpz/mailchimp-bundle symphony bundle allows us to interact with Mailchimp API.

Start adding this line on composer.json “require” section:

"require": {
    [...]
    "mlpz/mailchimp-bundle": "1.3"
}

After launch composer update command.

php composer.phar mlpz/mailchimp-bundle

Register this bundle on your symfony app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
[...]
        new \MZ\MailChimpBundle\MZMailChimpBundle()
    );

Add your mail chimp api key into app/config.yml (How to create an mail chimp api key)

mz_mail_chimp:
    api_key: this_is_your_key
    default_list: "this is your default list id"

Add this code on your controller

/** @var MailChimp $mailchimp */
 $mailchimp=$this->get("mailchimp");
 $campaign=$mailchimp->getCampaign();
 $campaign->setListId("the list id");
 $campaign->setType("regular");
 $campaign->setSubject("Email subject");
 $campaign->setFromEmail("Your@email.com");
 $campaign->setFromName("Your Name");
 $campaign->setHTML($emailbody);
 $id = $campaign->Create();
 $campaign->SendNow($id);

If you need extra documentation please check mail chimp bundle project or send a comment.

Write a Comment

Comment