PHP code example of mbouclas / mcms-mailchimp

1. Go to this page and download the library: Download mbouclas/mcms-mailchimp 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/ */

    

mbouclas / mcms-mailchimp example snippets


Newsletter::subscribe('[email protected]');

Newsletter::unsubscribe('[email protected]');

//Merge variables can be passed as the second argument
Newsletter::subscribe('[email protected]', ['firstName'=>'Sam', 'lastName'=>'Vines']);

//Subscribe someone to a specific list by using the third argument:
Newsletter::subscribe('[email protected]', ['firstName'=>'Nanny', 'lastName'=>'Ogg'], 'Name of your list');

//Get some member info, returns an array described in the official docs
Newsletter::getMember('[email protected]');

//Returns a boolean
Newsletter::hasMember('[email protected]');

//If you want to do something else, you can get an instance of the underlying API:
Newsletter::getApi();

// config/app.php
'providers' => [
    ...
    Mcms\Mailchimp\McmsMailchimpServiceProvider::class,
    ...
];

return [

        /*
         * The api key of a MailChimp account. You can find yours here:
         * https://us10.admin.mailchimp.com/account/api-key-popup/
         */
        'apiKey' => env('MAILCHIMP_APIKEY'),

        /*
         * When not specifying a listname in the various methods,
         *  this list name will be used.
         */
        'defaultListName' => 'subscribers',

        /*
         * Here you can define properties of the lists you want to
         * send campaigns.
         */
        'lists' => [

            /*
             * This key is used to identify this list. It can be used
             * in the various methods provided by this package.
             *
             * You can set it to any string you want and you can add
             * as many lists as you want.
             */
            'subscribers' => [

                /*
                 * A mail chimp list id. Check the mailchimp docs if you don't know
                 * how to get this value:
                 * http://kb.mailchimp.com/lists/managing-subscribers/find-your-list-id
                 */
                 'id' => env('MAILCHIMP_LIST_ID'),
            ],
        ],
];

use Newsletter;

use Newsletter;

Newsletter::subscribe('[email protected]');

Newsletter::unsubscribe('[email protected]');

Newsletter::subscribe('[email protected]', ['firstName'=>'Rince', 'lastName'=>'Wind']);

Newsletter::subscribe('[email protected]', ['firstName'=>'Rince', 'lastName'=>'Wind'], 'subscribers');

Newsletter::unsubscribe('[email protected]', 'subscribers');

Newsletter::delete('[email protected]');

Newsletter::getMember('[email protected]');

Newsletter::hasMember('[email protected]'); //returns a bool

/**
 * @param string $fromName
 * @param string $replyTo
 * @param string $subject
 * @param string $html
 * @param string $listName
 * @param array  $options
 * @param array  $contentOptions
 *
 * @return array|bool
 *
 * @throws \Mcms\Mailchimp\Exceptions\InvalidMailchimpList
 */
public function createCampaign($fromName, $replyTo, $subject, $html = '', $listName = '', $options = [], $contentOptions = [])

Newsletter::getLastError();

Newsletter::lastActionSucceeded(); //returns a bool

$api = Newsletter::getApi();
bash
php artisan vendor:publish --provider="Mcms\Mailchimp\McmsMailchimpServiceProvider"