承接 mailcraft/mailcraft-laravel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱: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

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固