PHP code example of mailmotor / mailmotor-bundle

1. Go to this page and download the library: Download mailmotor/mailmotor-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mailmotor / mailmotor-bundle example snippets


// In `app/AppKernel.php`
public function registerBundles()
{
    $bundles = array(
        // ...
        new MailMotor\Bundle\MailMotorBundle\MailMotorMailMotorBundle(),
        new MailMotor\Bundle\MailChimpBundle\MailMotorMailChimpBundle(),
    );

$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
);

$this->get('mailmotor.subscriber')->unsubscribe(
    $email,
    $listId // OPTIONAL, default listId is in your config parameters
);

$this->get('mailmotor.subscriber')->exists(
    $email,
    $listId // OPTIONAL, default listId is in your config parameters
);

$this->get('mailmotor.subscriber')->isSubscribed(
    $email,
    $listId // OPTIONAL, default listId is in your config parameters
);

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
    }
}

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
    }
}

public function registerBundles()
{
    $bundles = array(
        // ...
        new Crazy\Bundle\MailMotorBundle\CrazyMailMotorBundle(),
    );