PHP code example of locomotivemtl / charcoal-contrib-mailchimp

1. Go to this page and download the library: Download locomotivemtl/charcoal-contrib-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/ */

    

locomotivemtl / charcoal-contrib-mailchimp example snippets



class FooBar
{
    use MailchimpAwareTrait;
    [...]

    public function setDependencies(Container $container)
    {
        $this->setMailchimpListsMembers($container['mailchimp/lists/members']);
        [...]
    }
    
    public function run()
    {
        $user = [
            'email_address' => '[email protected]',
            'status' => 'pending',
            'merge_fields' => [
                'FNAME' => 'John',
                'LNAME' => 'Doe'
            ]
        ];
        
        // Set list ID
        $listId = 'a4029db2d';
        $this->mailchimpListsMembers()->setListId($listId);
        
        // Add/Create user
        $results = $this->mailchimpListsMembers()->add($user);
        
        // Add or Update user
        $results = $this->mailchimpListsMembers()->addOrUpdate($user);
        
        // Get a user's informations
        $results = $this->mailchimpListsMembers()->get('[email protected]');        
        
        // Delete a user from a list
        $results = $this->mailchimpListsMembers()->remove('[email protected]');
    }
}


// Get lists members
$this->mailchimp()->get('lists/{list_id}/members');

// Add member to list
$this->mailchimp()->post('list/{list_id}/members', [ 
    'email_address' => '[email protected]',
    'status' => 'pending'
]);