| Server IP : 54.94.228.101 / Your IP : 172.28.1.13 Web Server : Apache System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/vinumday2_0/vendor/nztim/mailchimp/ |
Upload File : |
# Mailchimp
Basic abstraction with Laravel integration for Mailchimp API v3
### Installation
- `composer require nztim/mailchimp`
- For Laravel 5 support:
- Add the service provider to `config/app.php`: `NZTim\Mailchimp\MailchimpServiceProvider::class,`
- Register the facade: `'Mailchimp' => NZTim\Mailchimp\MailchimpFacade::class,`
- Add `.env` value for `MC_KEY` (API key)
- Optionally publish the config file:
- `php artisan vendor:publish --provider=NZTim\Mailchimp\MailchimpServiceProvider`
### Usage
- Within Laravel 5, use the `Mailchimp` facade or inject `NZTim\Mailchimp\Mailchimp` using the container.
- Alternatively, instantiate using the API key: `$mc = new NZTim\Mailchimp\Mailchimp($apikey)`
```php
// Get an array of all available lists:
Mailchimp::getLists();
// Check to see if an email address is subscribed to a list:
Mailchimp::check($listId, $emailAddress); // Returns boolean
// Check the staus of a subscriber:
Mailchimp::status($listId, $emailAddress); // Returns 'subscribed', 'unsubscribed', 'cleaned', 'pending', 'transactional' or 'not found'
// Adds/updates an existing subscriber:
Mailchimp::subscribe($listId, $emailAddress, $merge = [], $confirm = true);
// Use $confirm = false to skip double-opt-in if you already have permission.
// This method will update an existing subscriber and will not ask an existing subscriber to re-confirm.
// Unsubscribe a member (set status to 'unsubscribed'):
Mailchimp::unsubscribe($listId, $emailAddress);
// Directly call the API:
Mailchimp::api($method, $endpoint, $data = []); // Returns an array.
```
For access to all the member properties available in the v3 API, use the Member class to subscribe and update list members:
```php
$member = (new NZTim\Mailchimp\Member($email))->merge(['FNAME' => 'First name'])->email_type('text')->confirm(false);
Mailchimp::addUpdateMember($member);
```
As with the `subscribe()` method, double-opt-in is default but existing members will not be asked to re-verify so you can use the same methods for create and update without needing to check.
### Errors
- Exceptions are thrown for all errors.
- Networking/communications errors will usually be of the type `Requests_Exception`.
- API errors will be of the base type `NZTim\Mailchimp\MailchimpException`, e.g. incorrect API key, list does not exist.
- `NZTim\Mailchimp\Exception\MailchimpBadRequestException` includes a `response()` method that returns the response body as an array.
- Gotchas: the API throws an error when you:
- Specify a merge field name with incorrect capitalisation
- Omit a required merge field when adding a new member
### Examples
```php
// Laravel:
// Subscribe a user to your list, existing subscribers will not receive confirmation emails
Mailchimp::subscribe('listid', 'user@domain.com');
// Subscribe a user to your list with merge fields and double-opt-in confirmation disabled
Mailchimp::subscribe('listid', 'user@domain.com', ['FNAME' => 'First name', 'LNAME' => 'Last name'], false);
// Subscribe/update a user using the Member class
$member = (new NZTim\Mailchimp\Member($email))->interests(['abc123fed' => true])->language('th');
Mailchimp::addUpdateMember('listid', $member);
```
### Upgrading
- To v3.0:
- Exceptions are now thrown for all errors, use try/catch where necessary
- Double-opt-in is now the default, update `Mailchimp::subscribe()` as required