Symfony Mime
Build and parse MIME messages, emails, and file type detection in PHP
Repository Health
Technical Analysis
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
Parthierarchy (TextPart,DataPart,Multipart\Alternative/Mixed/Related) for constructing arbitrary MIME structures beyond simple emails MimeTypeswith pluggable guessers (FileinfoMimeTypeGuesser,FileBinaryMimeTypeGuesser) for detecting a file’s MIME type from content or extensionHtmlToTextConverterfor 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 4 apps in this directory
Hyvor Relay
Devops · AI Development · Monitoring
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.
Kimai
Invoicing Finance · Project Management
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.
Mautic
Automation · Marketing · Ecommerce
The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.
wallabag
Bookmarks Archiving
Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.