定制 spatie/laravel-newsletter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

spatie/laravel-newsletter

Composer 安装命令:

composer require spatie/laravel-newsletter

包简介

Manage Mailcoach, MailChimp and MailerLite newsletters in Laravel

README 文档

README

Logo for laravel-newsletter

Manage newsletters in Laravel

Latest Version MIT Licensed run-tests PHPStan Total Downloads

This package provides an easy way to integrate subscriptions to email lists of various email services.

Currently this package support:

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install this package via Composer using:

composer require spatie/laravel-newsletter

To publish the config file to config/newsletter.php run:

php artisan vendor:publish --tag="newsletter-config"

This will publish a file newsletter.php in your config directory with the following contents:

return [

    /*
     * The driver to use to interact with MailChimp API.
     * You may use "log" or "null" to prevent calling the
     * API directly from your environment.
     */
    'driver' => env('NEWSLETTER_DRIVER', Spatie\Newsletter\Drivers\MailcoachDriver::class),

    /**
     * These arguments will be given to the driver.
     */
    'driver_arguments' => [
        'api_key' => env('NEWSLETTER_API_KEY'),

        'endpoint' => env('NEWSLETTER_ENDPOINT'),
    ],

    /*
     * The list name to use when no list name is specified in a method.
     */
    'default_list_name' => 'subscribers',

    'lists' => [

        /*
         * This key is used to identify this list. It can be used
         * as the listName parameter provided in the various methods.
         *
         * You can set it to any string you want and you can add
         * as many lists as you want.
         */
        'subscribers' => [

            /*
             * When using the Mailcoach driver, this should be the Email list UUID
             * which is displayed in the Mailcoach UI
             *
             * When using the MailChimp driver, this should be a MailChimp list id.
             * http://kb.mailchimp.com/lists/managing-subscribers/find-your-list-id.
             *
             * When using the MailerLite driver, this should be a MailerLite group id.
             */
            'id' => env('NEWSLETTER_LIST_ID'),
        ],
    ],
];

Using Mailcoach

To let this package work with Mailcoach, you need to install the Mailcoach SDK.

composer require spatie/mailcoach-sdk-php

Next, you must provide values for the API key, endpoint and list.subscribers.id in the config file. You'll find the API key and endpoint in the Mailcoach settings screen. The value for list.subscribers.id must be the UUID of an email list on Mailcoach. You'll find this value on the settings screen of an email list

Using MailChimp

To use MailChimp, install this extra package.

composer require drewm/mailchimp-api

The driver key of the newsletter config file must be set to Spatie\Newsletter\Drivers\MailChimpDriver::class.

Next, you must provide values for the API key and list.subscribers.id. You'll find these values in the MailChimp UI.

The endpoint config value must be set to null.

Using MailerLite

To use MailerLite, install this extra package.

composer require mailerlite/mailerlite-php

The driver key of the newsletter config file must be set to Spatie\Newsletter\Drivers\MailerLiteDriver::class.

You need to provide the API key and the group.id. These can be found in your MailerLite Dashboard under Integrations > API.

The endpoint config value must be set to null.

Usage

After you've installed the package and filled in the values in the config-file working with this package will be a breeze. All the following examples use the facade. Don't forget to import it at the top of your file.

use Spatie\Newsletter\Facades\Newsletter;

Subscribing, updating and unsubscribing

Subscribing an email address can be done like this:

use Newsletter;

Newsletter::subscribe('rincewind@discworld.com');

Let's unsubscribe someone:

Newsletter::unsubscribe('the.luggage@discworld.com');

For Mailcoach, you can pass extra attributes as the second argument:

Newsletter::subscribe('rincewind@discworld.com', ['first_name' => 'Rince', 'last_name' => 'Wind']);

For MailChimp you can pass merge variables as the second argument:

Newsletter::subscribe('rincewind@discworld.com', ['FNAME'=>'Rince', 'LNAME'=>'Wind']);

For MailerLite you can pass subscriber fields as the second argument:

Newsletter::subscribe('rincewind@discworld.com', ['name'=>'Rince', 'last_name'=>'Wind']);

You can subscribe someone to a specific list by passing a list name:

Newsletter::subscribe('rincewind@discworld.com', listName: 'subscribers');

That third argument is the name of a list you configured in the config file.

You can also subscribe and/or update someone. The person will be subscribed or updated if he/she is already subscribed:

Newsletter::subscribeOrUpdate('rincewind@discworld.com', ['first_name' => 'Rince', 'last_name' => 'Wind']);

For MailChimp, You can subscribe someone to one or more specific group(s)/interest(s) by using the fourth argument:

Newsletter::subscribeOrUpdate(
   'rincewind@dscworld.com', 
   ['FNAME'=>'Rince','LNAME'=>'Wind'], 
   'subscribers', 
   ['interests'=>['interestId'=>true, 'interestId'=>true]],
);

Simply add false if you want to remove someone from a group/interest.

Here's how to unsubscribe someone from a specific list:

Newsletter::unsubscribe('rincewind@discworld.com', 'subscribers');

For MailerLite, passing a list name as the second argument removes the subscriber from the matching group. Without a list name, the subscriber is marked as unsubscribed across the account.

Deleting subscribers

Deleting is not the same as unsubscribing. Unlike unsubscribing, deleting a member will result in the loss of all history (add/opt-in/edits) as well as removing them from the list. In most cases, you want to use unsubscribe instead of delete.

Here's how to perform a delete:

Newsletter::delete('rincewind@discworld.com');

Getting subscriber info

You can get information on a subscriber by using the getMember function:

Newsletter::getMember('lord.vetinari@discworld.com');

For MailCoach, this will return an instance of Spatie\Mailcoach\Resources|Subscriber For MailChimp, this will return an array with information on the subscriber.

If there's no one subscribed with that e-mail address the function will return false

There's also a convenient method to check if someone is already subscribed:

Newsletter::hasMember('nanny.ogg@discworld.com'); //returns a boolean

In addition to this, you can also check if a user is subscribed to your list:

Newsletter::isSubscribed('lord.vetinari@discworld.com'); //returns a boolean

Need something else?

If you need more functionality you get an instance of the underlying API with

$api = Newsletter::getApi();

If you're having trouble getting the MailChimp integration, you can see the last error with:

Newsletter::getApi()->getLastError();

Testing

Run the tests with:

vendor/bin/pest

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email security@spatie.be instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

spatie/laravel-newsletter 适用场景与选型建议

spatie/laravel-newsletter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.59M 次下载、GitHub Stars 达 1.63k, 最近一次更新时间为 2015 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「mailchimp」 「newsletter」 「laravel」 「mailerlite」 「mailcoach」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 spatie/laravel-newsletter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 spatie/laravel-newsletter 我们能提供哪些服务?
定制开发 / 二次开发

基于 spatie/laravel-newsletter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6.59M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1664
  • 点击次数: 33
  • 依赖项目数: 32
  • 推荐数: 1

GitHub 信息

  • Stars: 1634
  • Watchers: 37
  • Forks: 237
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-04