百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

mailchimp

> 后端框架
开源

Mailchimp API v3 Wrapper, 包括 Laravel 支持。

99 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

Mailchimp API v3 Wrapper, 包括 Laravel 支持。

Mailchimp

Basic abstraction with Laravel integration for Mailchimp API v3

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

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)
…

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_fields(['FNAME' => 'First name'])
    ->email_type('text')
    ->confirm(false);
Mailchimp::addUpdateMember($listId, $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 ConnectionException.
  • 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 attempts to provide the response body as an array, for automated handling of some error types.
  • Gotchas with merge fields:
    • If you receive an error adding a new subscriber, check for required merge fields.
    • Merge fields are case-sensitive.
    • Mailchimp::addUpdateMemberSkipMergeValidation() is available if needed.

Examples

php
// 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);

Upgrading

  • To v6.0: PHP 8.4 is required
  • To v5.0: PHP 8.1 is required
  • To v4.0:
    • PHP 7.4 | 8.0 is now required
    • Use unsub with archive in order to maximise the use of free accounts.
  • 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

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPlaravelmailchimpmailchimp-api

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架