v1.0.0 · MIT License · PHP 8.2+

Parse, Understand, and
Categorize Emails with One API

Open-source PHP library that transforms raw emails and EML files into structured business data — spam scores, invoices, orders, leads, phishing reports, and more.

Get Started → Live Preview API Reference
$ composer require mailsage/mailsage ⎘ copy Copied!
No SaaS No API Keys No Accounts PHP 8.2–8.4 PSR-12 PHPStan Max Framework Agnostic

Everything you need to understand email

One library. Zero external calls. Full intelligence from raw bytes to structured data.

📬
MIME Parser
Full multipart support — plain, HTML, mixed, alternative, related, and nested parts with base64 + quoted-printable decoding.
🚫
Spam Detection
0–100 scoring engine. Detects spam keywords, ALL CAPS abuse, shortened URLs, disposable domains, and phishing language.
🎣
Phishing Analysis
Sender mismatch detection, brand impersonation, suspicious URL analysis, and full security reports with risk levels.
🧾
Invoice Extraction
Detect and extract invoice number, date, total amount, currency, and vendor from billing emails automatically.
📦
Order Detection
Detect e-commerce orders from Shopify, WooCommerce, Magento, Amazon, eBay, Etsy, and generic platforms.
💼
Lead Extraction
Parse contact form submissions and business inquiry emails into structured leads with name, email, phone, and company.
🎧
Support Classification
Detect support requests and classify them: bug report, login issue, refund request, complaint, technical, or general.
🏷️
Categorization Engine
Classify any email into categories with confidence scores. Register custom categories with your own keyword rules.
📎
Attachment Risk Analysis
Extract attachments and assess their risk: safe, low, medium, high, or critical — based on extension and MIME type.

See MailSage in action

Real EML files from the test suite, parsed and analyzed.

📄 Email Source (EML)

    
⚡ MailSage Output
Output is a faithful simulation of what EmailParser::parse() returns for each fixture

Start in under 60 seconds

1Install via Composer

Requires PHP 8.2+, ext-mbstring, ext-json

composer require mailsage/mailsage
2Parse any email

Parse raw email strings or EML files with one call

EmailParser::parse($rawEmail)
3Extract intelligence

All detection is lazy-loaded. Zero configuration needed

$email->isInvoice(), ->invoice()
parse-invoice.php
use MailSage\EmailParser;

// Parse from raw email string
$email = EmailParser::parse($rawEmail);

// Or parse directly from an EML file
$email = EmailParser::fromFile('path/to/email.eml');

// Core fields
$email->subject();       // "Invoice INV-2026-0547"
$email->sender();        // ['name' => 'Acme Corp', 'email' => '...']
$email->body();          // Plain text body
$email->htmlBody();      // HTML body

// Intelligence
$email->category();      // "invoice"
$email->confidence();    // 95
$email->isSpam();        // false
$email->isPhishing();    // false
$email->isInvoice();     // true

// Invoice extraction
$invoice = $email->invoice();
$invoice->number();       // "INV-2026-0547"
$invoice->amount();       // 1595.00
$invoice->currency();     // "USD"
$invoice->vendor();       // "billing@acmecorp.com"

// Attachments
$email->attachments()->count();           // 1
$email->attachments()->highestRiskLevel();// "low"
$email->saveAttachments('/uploads');