定制 nextmigrant/laravel-sendy 二次开发

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

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

nextmigrant/laravel-sendy

最新稳定版本:v0.1.0

Composer 安装命令:

composer require nextmigrant/laravel-sendy

包简介

A generic Sendy email marketing API client for Laravel

README 文档

README

A reusable Laravel package that wraps the Sendy self-hosted email marketing API. It provides a clean SendyService class for subscribing/unsubscribing users, managing list membership, querying subscription statuses and active counts, and retrieving brand lists — all with a built-in production environment guard so no real API calls are ever made during development or testing.

Installation

composer require nextmigrant/laravel-sendy

Optionally publish the config file:

php artisan vendor:publish --tag=sendy-config

This creates config/sendy.php. You can also set everything via environment variables:

Variable Description
SENDY_ENABLED Enable or disable all API calls (default: true). Set to false in local/staging.
SENDY_API_KEY Your Sendy installation API key
SENDY_URL Base URL of your Sendy installation (e.g. https://sendy.yourdomain.com)
SENDY_NEW_USERS_LIST_ID List ID for the default "new signups" list

Usage

You can use the Sendy facade or inject/instantiate SendyService directly:

use NextMigrant\Sendy\Facades\Sendy;

// Via facade
$response = Sendy::subscribe('john@example.com', 'list-abc', 'John', 'Doe');
use NextMigrant\Sendy\SendyService;

// Via direct instantiation
$sendy = new SendyService;
$response = $sendy->subscribe('john@example.com', 'list-abc', 'John', 'Doe');

// Or via dependency injection (registered as a singleton)
public function __construct(private SendyService $sendy) {}

Note: All methods are guarded by the sendy.enabled config value. When set to false (via SENDY_ENABLED=false in your .env), methods return null (or [] for getLists) without making any API calls.

Subscribe

$response = $sendy->subscribe(
    email: 'john@example.com',
    listId: 'your-list-id',
    firstName: 'John',
    lastName: 'Doe',
);

// With optional full name and custom fields
$response = $sendy->subscribe(
    email: 'john@example.com',
    listId: 'your-list-id',
    firstName: 'John',
    lastName: 'Doe',
    fullName: 'Dr. John Doe',
    options: [
        'country' => 'CA',
        'gdpr' => 'true',
        'Birthday' => '1990-01-15',
    ],
);

Unsubscribe

$response = $sendy->unsubscribe('john@example.com', 'your-list-id');

Delete Subscriber

$response = $sendy->deleteSubscriber('john@example.com', 'your-list-id');

Get Subscription Status

$response = $sendy->getSubscriptionStatus('john@example.com', 'your-list-id');

// $response->message will be one of:
// Subscribed, Unsubscribed, Unconfirmed, Bounced, Soft bounced, Complained

Get Active Subscriber Count

$response = $sendy->getActiveSubscriberCount('your-list-id');

// $response->message contains the count as a string (e.g. "1523")

Get Lists

$lists = $sendy->getLists(brandId: 1);
// Returns: [['id' => 1, 'name' => 'Newsletter'], ...]

// Include hidden lists
$lists = $sendy->getLists(brandId: 1, includeHidden: true);

Response Object

All methods (except getLists) return a SendyResponse DTO:

use NextMigrant\Sendy\SendyResponse;

$response->success; // bool
$response->message; // string — "1" on success, or an error message

The static factory SendyResponse::fromApiResponse(string $body) treats "1" and "true" (case-insensitive) as success.

Testing

composer test

License

MIT

统计信息

  • 总下载量: 43
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固