mailcraft/mailcraft-laravel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mailcraft/mailcraft-laravel

Composer 安装命令:

composer require mailcraft/mailcraft-laravel

包简介

Official Laravel SDK for MailCraft — transactional email with AI-generated content

README 文档

README

Official Laravel SDK for MailCraft — open source transactional email with AI-generated content.

Installation

composer require mailcraft/mailcraft-laravel

Laravel auto-discovers the service provider and facade.

Configuration

Publish the config file:

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

Add your API key to .env:

MAILCRAFT_API_KEY=mc_your_api_key_here

If self-hosting:

MAILCRAFT_BASE_URL=https://your-mailcraft-instance.com

Usage

Fluent API (recommended)

use MailCraft\Facades\MailCraft;

MailCraft::create('welcome')
    ->to('john@example.com')
    ->data(['name' => 'John', 'plan' => 'Pro'])
    ->prompt('Mention dedicated support')
    ->action('Get Started', 'https://app.example.com')
    ->action('View Docs', 'https://docs.example.com', 'secondary')
    ->send();

Classic API

$result = MailCraft::send([
    'type'    => 'welcome',
    'to'      => 'john@example.com',
    'data'    => ['name' => 'John', 'plan' => 'Pro'],
    'prompt'  => 'Mention dedicated support',
    'actions' => [
        ['label' => 'Get Started', 'url' => 'https://app.example.com'],
    ],
]);

With Dependency Injection

use MailCraft\MailCraftClient;

class WelcomeController extends Controller
{
    public function __construct(private MailCraftClient $mail) {}

    public function send(): void
    {
        $this->mail->create('welcome')
            ->to('john@example.com')
            ->data(['name' => 'John'])
            ->send();
    }
}

Without Laravel (standalone)

use MailCraft\MailCraftClient;

$client = new MailCraftClient('mc_your_api_key');

$client->create('welcome')
    ->to('john@example.com')
    ->data(['name' => 'John'])
    ->send();

Fluent Builder Methods

Method Description
->to($email) Set recipient email
->data($array) Set dynamic template data
->prompt($string) Steer AI content generation
->action($label, $url, $style?) Add a CTA button (call multiple times)
->actions($array) Set all actions at once
->send() Send the email, returns ['id' => ..., 'status' => ...]

Options (Classic API)

Field Type Required Description
type string Yes Email type: 'welcome', 'invoice', 'password-reset', etc.
to string Yes Recipient email address
data array No Template variables
prompt string No AI content instructions
actions array No CTA buttons: [['label' => ..., 'url' => ..., 'style' => ...]]

Response

['id' => 'log_abc123', 'status' => 'sent']
// status: "sent" | "failed" | "fallback"

Error Handling

use MailCraft\Facades\MailCraft;
use MailCraft\MailCraftException;

try {
    MailCraft::create('welcome')
        ->to('john@example.com')
        ->send();
} catch (MailCraftException $e) {
    $e->getStatusCode(); // 401, 400, 502, etc.
    $e->getMessage();    // "Invalid API key"
    $e->getBody();       // Parsed response body
}

Self-Hosted

MAILCRAFT_BASE_URL=https://mail.internal.example.com

Or pass directly:

$client = new MailCraftClient('mc_your_key', 'https://mail.internal.example.com');

License

MIT

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

mailcraft/mailcraft-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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