Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mailmotor/campaignmonitor-bundle
(Un)Subscribing members to your CampaignMonitor Mailinglists very easily using this Symfony Bundle.
https://github.com/mailmotor/campaignmonitor-bundle
campaign-monitor campaignmonitor-bundle cm mail-engine mailinglist php symfony-bundle
Last synced: about 1 month ago
JSON representation
(Un)Subscribing members to your CampaignMonitor Mailinglists very easily using this Symfony Bundle.
- Host: GitHub
- URL: https://github.com/mailmotor/campaignmonitor-bundle
- Owner: mailmotor
- License: mit
- Created: 2015-12-01T13:26:59.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-03-13T16:30:56.000Z (almost 2 years ago)
- Last Synced: 2024-11-01T01:45:44.341Z (about 2 months ago)
- Topics: campaign-monitor, campaignmonitor-bundle, cm, mail-engine, mailinglist, php, symfony-bundle
- Language: PHP
- Homepage: https://packagist.org/packages/mailmotor/campaignmonitor-bundle
- Size: 33.2 KB
- Stars: 3
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CampaignMonitorBundle
[![Latest Stable Version](http://img.shields.io/packagist/v/mailmotor/campaignmonitor-bundle.svg)](https://packagist.org/packages/mailmotor/campaignmonitor-bundle)
[![License](http://img.shields.io/badge/license-MIT-lightgrey.svg)](https://github.com/mailmotor/campaignmonitor-bundle/blob/master/LICENSE)
[![Build Status](https://travis-ci.org/mailmotor/campaignmonitor-bundle.svg?branch=new-version)](https://travis-ci.org/mailmotor/campaignmonitor-bundle)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mailmotor/campaignmonitor-bundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mailmotor/campaignmonitor-bundle/?branch=master)> Subscribing/Unsubscribing to your own mailinglist has never been this easy! Thanks to this Symfony2 bundle.
## Examples
### Configure (CampaignMonitor)
```bash
composer require mailmotor/campaignmonitor-bundle
``````php
// In `app/AppKernel.php`
public function registerBundles()
{
$bundles = array(
// ...
new MailMotor\Bundle\MailMotorBundle\MailMotorMailMotorBundle(),
new MailMotor\Bundle\CampaignMonitorBundle\MailMotorCampaignMonitorBundle(),
);
``````yaml
# In `app/config/parameters.yml`
parameters:
# ...
mailmotor.mail_engine: 'campaignmonitor'
mailmotor.api_key: xxx # enter your campaignmonitor api_key here
mailmotor.list_id: xxx # enter the campaignmonitor default list_id here
```### Subscribing
```php
$this->get('mailmotor.subscriber')->subscribe(
$email, // f.e.: '[email protected]'
$language, // f.e.: 'nl'
$mergeFields, // f.e.: ['FNAME' => 'Jeroen', 'LNAME' => 'Desloovere']
$interests, // f.e.: ['9A28948d9' => true, '8998ASAA' => false]
$doubleOptin, // OPTIONAL, default = true
$listId // OPTIONAL, default listId is in your config parameters
);
```### Unsubscribing
```php
$this->get('mailmotor.subscriber')->unsubscribe(
$email,
$listId // OPTIONAL, default listId is in your config parameters
);
```### Exists
```php
$this->get('mailmotor.subscriber')->exists(
$email,
$listId // OPTIONAL, default listId is in your config parameters
);
```### Is subscribed
```php
$this->get('mailmotor.subscriber')->isSubscribed(
$email,
$listId // OPTIONAL, default listId is in your config parameters
);
```### Full example for subscribing
```php
use MailMotor\Bundle\MailMotorBundle\Exception\NotImplementedException;// Don't forget to add validation to your $email
$email = '[email protected]';try {
if ($this->get('mailmotor.subscriber')->isSubscribed($email)) {
// Add error to your form
}
// Fallback for when no mailmotor parameters are defined
} catch (NotImplementedException $e) {
// Do nothing
}if ($noErrors)
try {
// Subscribe the user to our default group
$this->get('mailmotor.subscriber')->subscribe(
$email,
$language,
$mergeFields
);
// Fallback for when no mailmotor parameters are defined
} catch (NotImplementedException $e) {
// Add you own code here to f.e.: send a mail to the admin
}
}
```### Full example for unsubscribing
```php
use MailMotor\Bundle\MailMotorBundle\Exception\NotImplementedException;// Don't forget to add validation to your $email
$email = '[email protected]';try {
// Email exists
if ($this->get('mailmotor.subscriber')->exists($email)) {
// User is already unsubscribed
if ($this->get('mailmotor.subscriber')->isUnsubscribed($email)) {
// Add error to your form: "User is already unsubscribed"
}
// Email not exists
} else {
// Add error to your form: "email is not in mailinglist"
}
// Fallback for when no mailmotor parameters are defined
} catch (NotImplementedException $e) {
// Do nothing
}if ($noErrors) {
try {
// Unsubscribe the user
$this->get('mailmotor.subscriber')->unsubscribe($email);
// Fallback for when no mailmotor parameters are defined
} catch (NotImplementedException $e) {
// We can send a mail to the admin instead
}
}
```## Extending
### Creating a bundle for another mail engine.
F.e.: You want to use a mail engine called "Crazy".
```php
public function registerBundles()
{
$bundles = array(
// ...
new Crazy\Bundle\MailMotorBundle\CrazyMailMotorBundle(),
);
```In **app/config/parameters.yml**
```yaml
mailmotor.mail_engine: 'crazy'
mailmotor.api_key: xxx # enter your crazy api_key here
mailmotor.list_id: xxx # enter the crazy default list_id here
```Then you just need to duplicate all files from another mail engine, like f.e.: "mailmotor/campaignmonitor-bundle" and replace all the logic for your own mail engine.
## Credits
* Jeroen Desloovere - [Github](https://github.com/jeroendesloovere), [Website](http://jeroendesloovere.be)