mailcraft / mailcraft-laravel
Official Laravel SDK for MailCraft — transactional email with AI-generated content
dev-main
2026-03-28 15:58 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
This package is not auto-updated.
Last update: 2026-05-10 14:16:38 UTC
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