PHP code example of mailoptin / mailchimp-api-php

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

    

mailoptin / mailchimp-api-php example snippets



key = 'YOUR_API_KEY';
$mailchimp = new Mailchimp\Mailchimp($api_key);

// Get the account details of the authenticated user.
$response = $mailchimp->getAccount();

// Output the account details.
if (!empty($response) && isset($response->account_id)) {
  echo "ID: {$response->account_id}\n"
  . "Name: {$response->account_name}\n";
}


key = 'YOUR_API_KEY';
$mailchimp_lists = new Mailchimp\MailchimpLists($api_key);

// Get all lists.
$response = $mailchimp_lists->getLists();

if (!empty($response) && isset($response->lists)) {
  foreach ($response->lists as $list) {
    // Output the list name.
    echo "List name: {$list->name}\n";

    // Get the list's interest categories.
    $interests = $mailchimp_lists->getInterestCategories($list->id);

    // Output the names of the list's interest categories.
    if (!empty($interests) && isset($interests->categories)) {
      foreach ($interests->categories as $category) {
        echo "Interest category: {$category->title}\n";
      }
    }
  }
}