PHP code example of blenderdeluxe / mailchimpv3-laravel

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

    

blenderdeluxe / mailchimpv3-laravel example snippets


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

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

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

	/**
	 * Add a subscriber in a list
     * for more info check "http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/"
	 */
	public function addEmailToList($email)
	{
		try {
			$result = $this->mailChimp->post("lists/" . $this->listId . "/members", [
                'email_address' => $email,
                'status'        => 'subscribed',
            ]);
        } catch (\Exception $e) {
        	// do something
        }
	}

	/**
	 * Get lists
     * for more info check "http://developer.mailchimp.com/documentation/mailchimp/reference/lists/"
	 */
	public function getLists()
	{
		try {
			$result = $this->mailChimp->get("lists");
        } catch (\Exception $e) {
        	// do something
        }
	}
}

config/app.php

php artisan vendor:publish --provider="Fraterblack\Mailchimp\MailchimpServiceProvider"