Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Mail Mime Parser

Mail Mime Parser Laravel Package

zbateson/mail-mime-parser

PSR-compliant, testable MIME email parser for PHP 8.1+ as an alternative to imap* and PEAR. Parses RFC 822/2822/5322 messages from strings, resources, or PSR-7 streams; standards-compliant yet forgiving, with a cleaned-up 4.x API.

View on GitHub
Deep Wiki
Context7

zbateson/mail-mime-parser is a PSR-compliant, testable alternative to PHP’s imap* functions and legacy PEAR libs for parsing email messages in Internet Message Format (RFC 822/2822/5322). It focuses on standards correctness while remaining forgiving with real-world MIME, and provides a clean API for working with headers, bodies, and attachments.

  • Parse from a string, resource, or PSR-7 StreamInterface
  • Access normalized headers and decoded header values
  • Read text/HTML bodies and traverse MIME parts
  • Handle attachments/inline parts and content transfer encodings
  • PHP 8.1+ with improved configurability in v4.x
Frequently asked questions about Mail Mime Parser
Can I use zbateson/mail-mime-parser to parse inbound emails in Laravel without SwiftMailer?
Yes, this package is designed for parsing raw email messages in Internet Message Format (RFC 822/5322), making it ideal for processing inbound emails like notifications or user messages. It’s a standalone parser and doesn’t replace SwiftMailer, which focuses on sending emails. Use it alongside Laravel’s Mail facade for a complete workflow.
How do I install and set up zbateson/mail-mime-parser in a Laravel project?
Install via Composer with `composer require zbateson/mail-mime-parser`. No additional Laravel-specific setup is required, but you may want to bind the parser to Laravel’s service container manually for dependency injection. The package works with PSR-7 streams, so it integrates seamlessly with Laravel’s HTTP layer for parsing raw email payloads.
Does zbateson/mail-mime-parser support Laravel’s queue system for processing emails asynchronously?
The package itself doesn’t include native Laravel queue integration, but you can wrap parsing logic in a job (e.g., `ParseEmailJob`) and dispatch it via Laravel Queues. This allows background processing of emails, especially useful for high-volume systems. The parser’s lightweight design makes it ideal for queued operations.
What Laravel versions are compatible with zbateson/mail-mime-parser v4.x?
Version 4.x requires PHP 8.1+, which aligns with Laravel 9+ and later. If you’re using Laravel 8.x or earlier, you’ll need to stick with v3.x of the package. Always check the package’s [upgrade guide](https://mail-mime-parser.org/upgrade-4.0) for migration details if switching versions.
How do I handle large email attachments or nested MIME structures with this parser?
The parser supports streaming attachments via PSR-7 `StreamInterface`, which helps manage memory for large files. For nested MIME structures, traverse the `IMessage` object’s parts recursively. If performance is critical, consider processing emails in chunks or using Laravel’s queue system to avoid memory overload.
Can I use zbateson/mail-mime-parser to validate SPF/DKIM headers for email security?
This package focuses on parsing and extracting email content, not validation. For SPF/DKIM checks, you’ll need additional libraries like `spatie/laravel-mail` or `egulias/email-validator`. However, the parser provides normalized headers, making it easier to integrate with validation tools.
Is there a Laravel facade or service provider for zbateson/mail-mime-parser?
No, the package doesn’t include Laravel-specific facades or service providers. You’ll need to manually bind the `MailMimeParser` class to Laravel’s container if you want to use it as a singleton. This gives you flexibility but requires a few lines of setup in a service provider.
How do I test email parsing logic with zbateson/mail-mime-parser in Laravel?
The package includes a built-in test suite (PHPUnit) for unit testing. For Laravel integration tests, mock PSR-7 streams or use temporary files to simulate email inputs. You can also leverage Laravel’s testing helpers to assert parsed headers, bodies, or attachments against expected values.
Are there alternatives to zbateson/mail-mime-parser for parsing emails in Laravel?
Yes, alternatives include `spatie/laravel-mail` (for sending/receiving emails) or `php-mime-mail-parser` (a lower-level library). However, `zbateson/mail-mime-parser` stands out for its RFC 5322 compliance, PSR-7 compatibility, and modern PHP 8.1+ optimizations, making it a robust choice for parsing complex MIME emails.
How do I handle encrypted emails (S/MIME or PGP) with this parser?
The base package doesn’t decrypt emails, but it includes support for plugins like `mmp-crypt-*` for S/MIME and PGP. These companion packages extend the parser’s functionality. For Laravel integration, you’d need to manually handle decryption logic, possibly by dispatching decryption jobs or using middleware.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport