Reputation: 29
I have tried this code
$listId = 'xxxxxxxxxxxx';
//Mailchimp instantiation with Key
$mailchimp = new \Mailchimp('xxxxxxxxxxxxxxxxxxxxxxxx-xxx');
$mailchimp->from('xxxxxxxxxxxxxxx');
$mailchimp->reply_to('xxxxxxxxxxxxxxxx');
$mailchimp->to($email->email);
$mailchimp->subject('x');xxxxxxxxxxxxx
$mailchimp->message('<html>hiiiii</html');
$mailchimp->set_header('Content-type', 'text/html');
$mailchimp->send();
Upvotes: 1
Views: 4256
Reputation: 802
Mailchimp Installation
composer require nztim/mailchimp
For Laravel support:
Laravel 5.5+ will auto-discover the package, for earlier versions you will need to:
Add the service provider to config/app.php:
NZTim\Mailchimp\MailchimpServiceProvider::class,
Register the facade: 'Mailchimp' => NZTim\Mailchimp\MailchimpFacade::class,
Add an .env value for MC_KEY (your API key)
Optionally, publish the config file:
php artisan vendor:publish --provider=NZTim\Mailchimp\MailchimpServiceProvider
Code Email: -
$member = (new NZTim\Mailchimp\Member($email))->merge_fields(['FNAME' => 'First name'])->email_type('text')->confirm(false);
Mailchimp::addUpdateMember($member);
Examples
// Laravel:
// Subscribe a user to your list, existing subscribers will not receive confirmation emails
Mailchimp::subscribe('listid', '[email protected]');
// Subscribe a user to your list with merge fields and double-opt-in confirmation disabled
Mailchimp::subscribe('listid', '[email protected]', ['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);
Errors
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
Upvotes: 2