Symfony Mime

Build and parse MIME messages, emails, and file type detection in PHP

Library
Composer
vv8.1.7
2,829 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
87 /100 Excellent
Development Activity 92
Maintenance 100
Community 56
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
83 /100 Excellent
Architecture 88
Code Quality 90
Innovation 75
Learning Curve 78

Symfony Mime is the standalone PHP component behind email and MIME-message construction across the Symfony ecosystem, most visibly powering symfony/mailer. It models a MIME message as a composable tree of typed parts — TextPart, DataPart (attachments), Multipart\Alternative/Mixed/Related — with an Email builder class on top that handles the common case of subject, from/to addresses, HTML/plain-text bodies, attachments, and embedded images without requiring callers to hand-construct headers or multipart boundaries.

Beyond message assembly, the component ships a MimeTypes registry that guesses a file’s MIME type either from its extension or, via FileinfoMimeTypeGuesser/FileBinaryMimeTypeGuesser, by inspecting file contents directly (using PHP’s fileinfo extension or a file binary fallback). It also includes an HtmlToTextConverter for auto-generating plain-text alternatives from HTML bodies, S/MIME signing and encryption support in Crypto/, and header classes for every RFC-defined MIME header type (mailbox lists, structured/unstructured headers, parameterized headers), making it usable independently as a general MIME-handling toolkit, not just as an email builder.

What You Get

  • Email — a high-level builder for subject, addresses, HTML/plain-text bodies, attachments, and embedded inline images, without manually assembling multipart structures
  • A composable Part hierarchy (TextPart, DataPart, Multipart\Alternative/Mixed/Related) for constructing arbitrary MIME structures beyond simple emails
  • MimeTypes with pluggable guessers (FileinfoMimeTypeGuesser, FileBinaryMimeTypeGuesser) for detecting a file’s MIME type from content or extension
  • HtmlToTextConverter for generating a plain-text alternative body automatically from an HTML email
  • S/MIME signing and encryption support (Crypto/SMimeSigner, SMimeEncrypter) plus a full set of RFC-compliant header classes (mailbox, date, identification, parameterized headers)

Common Use Cases

  • Composing transactional or marketing emails with HTML bodies, plain-text fallbacks, attachments, and embedded images via symfony/mailer
  • Detecting a file’s MIME type reliably from its actual content (not just extension) for upload validation or content-disposition headers
  • Signing or encrypting outgoing email content with S/MIME for compliance-sensitive applications
  • Parsing or generating multipart MIME payloads outside of email — any application needing RFC 2045-compliant message structures

Under The Hood

Architecture — The component models a MIME message as a tree of Part objects (AbstractPart.php as the base, TextPart.php and DataPart.php as leaves, Multipart/ subclasses as composite nodes implementing alternative/mixed/related semantics), with Email.php acting as a builder facade that assembles the correct part tree from a simpler subject/body/attachment API and Message.php/RawMessage.php handling serialization to the raw RFC 2045 wire format. Tech Stack — Pure PHP 8.4+ with only two runtime dependencies (symfony/polyfill-intl-idn, symfony/polyfill-mbstring), keeping the component usable outside the full Symfony framework; dev dependencies (egulias/email-validator, league/html-to-markdown) are wired in only for optional integrations like address validation and HTML-to-text conversion. Code Quality — 45 PHPUnit test files exercise the part hierarchy, header parsing/encoding, MIME-type guessers, and S/MIME crypto; the codebase follows Symfony’s long-standing component conventions (PSR-4 autoloading under Symfony\Component\Mime\, strict interface segregation via MimeTypesInterface/HeaderInterface/BodyRendererInterface) and is one of the most heavily used components in the ecosystem (15.7M monthly installs), which keeps its API surface unusually stable. API Design — The Email builder class collapses what would otherwise be manual multipart/header construction into a fluent, chainable API (->subject()->from()->to()->html()->attach()), while the lower-level Part/Header classes remain available for callers who need to construct non-email MIME structures directly — giving both a low-friction common path and full control when needed.

Used by 5 apps in this directory

PHP
63%
AGPL 3.0

Hyvor Relay

AI Development · Devops · Monitoring

908

Self-hosted, open-source email API that automates DNS, manages SMTP delivery, and provides deep observability — replacing SES, Mailgun, and SendGrid with infrastructure you fully own.

View details
68
Repo Health
79
Technical
70
Dependency
Built with
PHP 63%
Svelte 23%
Go 11%
Updated 1 weeks ago
PHP
86%
AGPL 3.0

Kimai

Invoicing Finance · Project Management

5,046

Professional open-source time tracking with invoicing, multi-user support, SAML/LDAP auth, and a full REST API—self-host it or use the cloud.

View details
94
Repo Health
78
Technical
64
Dependency
Built with
PHP 86%
Updated 4 days ago
TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,043

Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.

View details
70
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 1 months ago
PHP
82%
Other

Mautic

Automation · Ecommerce · Marketing

10,570

The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.

View details
97
Repo Health
76
Technical
63
Dependency
Built with
PHP 82%
Updated 1 weeks ago
PHP
84%
MIT

wallabag

Bookmarks Archiving

12,989

Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.

View details
93
Repo Health
81
Technical
59
Dependency
Built with
PHP 84%
Twig 13%
Updated 4 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers