PHP code example of digiageltd / mailchimp-laravel

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

    

digiageltd / mailchimp-laravel example snippets


class NewsletterManager
{
    protected $mailchimp;
    protected $listId = '1234567890';        // Id of newsletter list

    /**
     * Pull the Mailchimp-instance from the IoC-container.
     */
    public function __construct(\Mailchimp $mailchimp)
    {
        $this->mailchimp = $mailchimp;
    }

    /**
     * Access the mailchimp lists API
     */
    public function addEmailToList($email)
    {
        try {
            $this->mailchimp
              ->lists
              ->subscribe(
                $this->listId,
                ['email' => $email]
              );
        } catch (\Mailchimp_List_AlreadySubscribed $e) {
            // do something
        } catch (\Mailchimp_Error $e) {
            // do something
        }
    }
}

'providers' => [
  Skovmand\Mailchimp\MailchimpServiceProvider::class,
]

MAILCHIMP_API_KEY="your-api-key-here"
config/app.php

php artisan vendor:publish --provider="Skovmand\Mailchimp\MailchimpServiceProvider"
config/mailchimp.php