sreedev/laravel-mailchimp
Composer 安装命令:
composer require sreedev/laravel-mailchimp
包简介
Laravel MailChimp Package
README 文档
README
Super-simple, minimum abstraction MailChimp API v3 library for Laravel
Please refer MailChimp API docs to get to know more about the methods available
Requires PHP 7.2+
Installation
You can install laravel-mailchimp using Composer:
composer require sreedev/laravel-mailchimp
You will then need to:
- run
composer installto get these dependencies added to your vendor directory - publish the config to your application with this line:
php artisan vendor:publish --provider="Sreedev\MailChimp\MailChimpServiceProvider" --tag="config" - set the
MAIL_CHIMP_API_KEY="<YOUR_API_KEY>"in the .env file
Examples
Start by use-ing the library by adding use
use Sreedev\MailChimp\Facades\MailChimp;
Then, list all the mailing lists (with a get on the lists method)
$result = MailChimp::get('lists'); print_r($result);
Subscribe someone to a list (with a post to the lists/{listID}/members method):
$list_id = 'b1234346'; $result = MailChimp::post("lists/$list_id/members", [ 'email_address' => 'member@example.com', 'status' => 'subscribed', ]); print_r($result);
Update a list member with more information (using patch to update):
$list_id = 'b1234346'; $subscriber_hash = MailChimp::subscriberHash('subscriber@example.com'); $result = MailChimp::patch("lists/$list_id/members/$subscriber_hash", [ 'merge_fields' => ['FNAME'=>'First', 'LNAME'=>'Man'], 'interests' => ['2s3a384h' => true], ]); print_r($result);
Remove a list member using the delete method:
$list_id = 'b1234346'; $subscriber_hash = MailChimp::subscriberHash('subscriber@example.com'); MailChimp::delete("lists/$list_id/members/$subscriber_hash");
Quickly test for a successful action with the success() method:
$list_id = 'b1234346'; $result = MailChimp::post("lists/$list_id/members", [ 'email_address' => 'subscriber@example.com', 'status' => 'subscribed', ]); if (MailChimp::success()) { print_r($result); } else { echo MailChimp::getLastError(); }
Batch Operations
The MailChimp Batch Operations this enables you to complete multiple operations with a single call. Eg: Adding thousands of members to a list - you can perform this in one request rather than thousands.
use Sreedev\MailChimp\Facades\MailChimp; $Batch = MailChimp::newBatch()
You need to set an ID for the operation as the first argument, and also that you won't get a response. The ID is used for finding the result of this request in the combined response from the batch operation.
$list_id ="abcd"; $Batch->post("op1", "lists/$list_id/members", [ 'email_address' => 'subscriber1@example.com', 'status' => 'subscribed', ]); $Batch->post("op2", "lists/$list_id/members", [ 'email_address' => 'subscriber2@example.com', 'status' => 'subscribed', ]); $Batch->post("op3", "lists/$list_id/members", [ 'email_address' => 'subscriber3@example.com', 'status' => 'subscribed', ]);
Once you've finished all the requests that should be in the batch, you need to process it.
$result = $Batch->process();
The result includes a batch ID. At a later point, you can check the status of your batch:
MailChimp::newBatch($batchId); $result = $Batch->checkStatus();
When your batch is finished, you can download the results (in JSON format) from the URL given in the response.
Troubleshooting
To get the last error returned by either the HTTP client or by the API, use getLastError():
echo MailChimp::getLastError();
For further debugging, you can inspect the headers and body of the response:
print_r(MailChimp::getLastResponse());
If you suspect you're sending data in the wrong format, you can look at what was sent to MailChimp by the wrapper:
print_r(MailChimp::getLastRequest());
If your server's CA root certificates are not up to date you may find that SSL verification fails and you don't get a response. The correction solution for this is not to disable SSL verification. The solution is to update your certificates.
Contributing
This is a simple wrapper, but contributions can make it beeter. If you'd like to suggest an improvement, please raise an issue to discuss it before making your pull request.
Pull requests for bugs are more than welcome - please explain the bug you're trying to fix in the message.
sreedev/laravel-mailchimp 适用场景与选型建议
sreedev/laravel-mailchimp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.17k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 06 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 sreedev/laravel-mailchimp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sreedev/laravel-mailchimp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.17k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-09