PHPackages                             zbateson/mail-mime-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. zbateson/mail-mime-parser

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

zbateson/mail-mime-parser
=========================

MIME email message parser

4.0.1(2mo ago)54149.2M—2.6%59[20 issues](https://github.com/zbateson/mail-mime-parser/issues)20BSD-2-ClausePHPPHP &gt;=8.1CI failing

Since Nov 23Pushed 2mo ago22 watchersCompare

[ Source](https://github.com/zbateson/mail-mime-parser)[ Packagist](https://packagist.org/packages/zbateson/mail-mime-parser)[ Docs](https://mail-mime-parser.org)[ GitHub Sponsors](https://github.com/zbateson)[ RSS](/packages/zbateson-mail-mime-parser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (18)Versions (73)Used By (20)

zbateson/mail-mime-parser
=========================

[](#zbatesonmail-mime-parser)

Testable and PSR-compliant mail mime parser alternative to PHP's imap\* functions and Pear libraries for reading messages in *Internet Message Format* [RFC 822](http://tools.ietf.org/html/rfc822) (and later revisions [RFC 2822](http://tools.ietf.org/html/rfc2822), [RFC 5322](http://tools.ietf.org/html/rfc5322)).

[![Build Status](https://github.com/zbateson/mail-mime-parser/actions/workflows/tests.yml/badge.svg)](https://github.com/zbateson/mail-mime-parser/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/d902baa744d2342ff346ec2b640b3c8ec31ca29511d5a4e176f6570bb31c49da/68747470733a2f2f706f7365722e707567782e6f72672f7a62617465736f6e2f6d61696c2d6d696d652d7061727365722f646f776e6c6f616473)](//packagist.org/packages/zbateson/mail-mime-parser)[![Latest Stable Version](https://camo.githubusercontent.com/0df42d008752101f95995fd439af19756d17944a48c235657df2edccc12166a8/68747470733a2f2f706f7365722e707567782e6f72672f7a62617465736f6e2f6d61696c2d6d696d652d7061727365722f76)](//packagist.org/packages/zbateson/mail-mime-parser)

The goals of this project are to be:

- Well written
- Standards-compliant but forgiving
- Tested where possible

To include it for use in your project, install it via composer:

```
composer require zbateson/mail-mime-parser

```

Sponsors
--------

[](#sponsors)

[![SecuMailer](https://camo.githubusercontent.com/74de27677ddf07fa571fcca6558d34be0fa6486bf473de73261461b89b12e8c5/68747470733a2f2f6d61696c2d6d696d652d7061727365722e6f72672f73706f6e736f72732f6c6f676f2d736563756d61696c65722e706e67)](https://secumailer.com)

A huge thank you to [all my sponsors](https://github.com/sponsors/zbateson). &lt;3

If this project's helped you, please consider [sponsoring me](https://github.com/sponsors/zbateson).

New in 4.0
----------

[](#new-in-40)

Version 4.0 requires PHP 8.1+ and focuses on API cleanup and improved configurability. For details, see the [4.0 Upgrade Guide](https://mail-mime-parser.org/upgrade-4.0).

Requirements
------------

[](#requirements)

MailMimeParser requires PHP 8.1 or newer. Tested on PHP 8.1, 8.2, 8.3, 8.4 and 8.5.

Usage
-----

[](#usage)

```
use ZBateson\MailMimeParser\MailMimeParser;
use ZBateson\MailMimeParser\Message;
use ZBateson\MailMimeParser\Header\HeaderConsts;

// use an instance of MailMimeParser as a class dependency
$mailParser = new MailMimeParser();

// parse() accepts a string, resource or Psr7 StreamInterface
// pass `true` as the second argument to attach the passed $handle and close
// it when the returned IMessage is destroyed.
$handle = fopen('file.mime', 'r');
$message = $mailParser->parse($handle, false);         // returns `IMessage`

// OR: use this procedurally (Message::from also accepts a string,
// resource or Psr7 StreamInterface
// true or false as second parameter doesn't matter if passing a string.
$string = "Content-Type: text/plain\r\nSubject: Test\r\n\r\nMessage";
$message = Message::from($string, false);

echo $message->getHeaderValue(HeaderConsts::FROM);     // user@example.com
echo $message
    ->getHeader(HeaderConsts::FROM)                    // AddressHeader
    ->getPersonName();                                 // Person Name
echo $message->getSubject();                           // The email's subject
echo $message
    ->getHeader(HeaderConsts::TO)                      // also AddressHeader
    ->getAddresses()[0]                                // AddressPart
    ->getPersonName();                                 // Person Name
echo $message
    ->getHeader(HeaderConsts::CC)                      // also AddressHeader
    ->getAddresses()[0]                                // AddressPart
    ->getEmail();                                      // user@example.com

echo $message->getTextContent();                       // or getHtmlContent()

echo $message->getHeader('X-Foo');                     // for custom or undocumented headers

$att = $message->getAttachmentPart(0);                 // first attachment
echo $att->getHeaderValue(HeaderConsts::CONTENT_TYPE); // e.g. "text/plain"
echo $att->getHeaderParameter(                         // value of "charset" part
    HeaderConsts::CONTENT_TYPE,
    'charset'
);
echo $att->getContent();                               // get the attached file's contents
$stream = $att->getContentStream();                    // the file is decoded automatically
$dest = \GuzzleHttp\Psr7\stream_for(
    fopen('my-file.ext')
);
\GuzzleHttp\Psr7\copy_to_stream(
    $stream, $dest
);
// OR: more simply if saving or copying to another stream
$att->saveContent('my-file.ext');               // writes to my-file.ext
$att->saveContent($stream);                     // copies to the stream

// close only when $message is no longer being used.
fclose($handle);
```

Encryption and Signing Plugins
------------------------------

[](#encryption-and-signing-plugins)

Optional companion packages add S/MIME and PGP/MIME support for decrypting, encrypting, signing and verifying messages:

- [zbateson/mmp-crypt-smime](https://github.com/zbateson/mmp-crypt-smime) -- S/MIME via PHP's OpenSSL extension
- [zbateson/mmp-crypt-gpg](https://github.com/zbateson/mmp-crypt-gpg) -- PGP/MIME via PEAR's Crypt\_GPG

Install either package and encrypted/signed messages are automatically detected and decrypted during parsing. See the [Usage Guide](https://mail-mime-parser.org/#encryption-and-signing)for examples of reading encrypted messages and composing signed/encrypted ones.

Documentation
-------------

[](#documentation)

- [Usage Guide](https://mail-mime-parser.org/)
- [API Reference](https://mail-mime-parser.org/api/4.0)

Upgrade guides
--------------

[](#upgrade-guides)

- [1.x Upgrade Guide](https://mail-mime-parser.org/upgrade-1.0)
- [2.x Upgrade Guide](https://mail-mime-parser.org/upgrade-2.0)
- [3.x Upgrade Guide](https://mail-mime-parser.org/upgrade-3.0)
- [4.x Upgrade Guide](https://mail-mime-parser.org/upgrade-4.0)

License
-------

[](#license)

BSD licensed - please see [license agreement](https://github.com/zbateson/mail-mime-parser/blob/master/LICENSE).

###  Health Score

76

—

ExcellentBetter than 100% of packages

Maintenance86

Actively maintained with recent releases

Popularity72

Solid adoption and visibility

Community45

Growing community involvement

Maturity87

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 90.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~53 days

Recently: every ~144 days

Total

72

Last Release

68d ago

Major Versions

1.3.2 → 2.0.0-beta2021-08-06

1.3.3 → 2.0.12021-11-07

2.4.0 → 3.0.0-beta2024-04-15

2.4.1 → 3.0.12024-04-29

3.0.5 → 4.0.02026-02-13

PHP version history (5 changes)0.1.0PHP &gt;=5.5.0

0.1.1PHP &gt;=5.4

2.3.0PHP &gt;=7.1

3.0.0-betaPHP &gt;=8.0

4.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/f2d1f00c58c63c29cc0fcf5972c9add3d468fb126f7191a6a5dfabc1f0af24e4?d=identicon)[zbateson](/maintainers/zbateson)

---

Top Contributors

[![zbateson](https://avatars.githubusercontent.com/u/8356974?v=4)](https://github.com/zbateson "zbateson (874 commits)")[![phpfui](https://avatars.githubusercontent.com/u/7434059?v=4)](https://github.com/phpfui "phpfui (30 commits)")[![ThomasLandauer](https://avatars.githubusercontent.com/u/1054469?v=4)](https://github.com/ThomasLandauer "ThomasLandauer (29 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (6 commits)")[![mariuszkrzaczkowski](https://avatars.githubusercontent.com/u/10198654?v=4)](https://github.com/mariuszkrzaczkowski "mariuszkrzaczkowski (4 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (3 commits)")[![pableu](https://avatars.githubusercontent.com/u/305859?v=4)](https://github.com/pableu "pableu (2 commits)")[![i-tabu](https://avatars.githubusercontent.com/u/9974389?v=4)](https://github.com/i-tabu "i-tabu (2 commits)")[![MatthiasKuehneEllerhold](https://avatars.githubusercontent.com/u/19988979?v=4)](https://github.com/MatthiasKuehneEllerhold "MatthiasKuehneEllerhold (2 commits)")[![tivnet](https://avatars.githubusercontent.com/u/1696330?v=4)](https://github.com/tivnet "tivnet (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![ondrejmirtes](https://avatars.githubusercontent.com/u/104888?v=4)](https://github.com/ondrejmirtes "ondrejmirtes (1 commits)")[![pupaxxo](https://avatars.githubusercontent.com/u/2815664?v=4)](https://github.com/pupaxxo "pupaxxo (1 commits)")[![seanmckenzie428](https://avatars.githubusercontent.com/u/70048908?v=4)](https://github.com/seanmckenzie428 "seanmckenzie428 (1 commits)")[![Stefaans](https://avatars.githubusercontent.com/u/4809513?v=4)](https://github.com/Stefaans "Stefaans (1 commits)")[![styks1111](https://avatars.githubusercontent.com/u/642930?v=4)](https://github.com/styks1111 "styks1111 (1 commits)")[![SunMar](https://avatars.githubusercontent.com/u/8324268?v=4)](https://github.com/SunMar "SunMar (1 commits)")[![erlangsec](https://avatars.githubusercontent.com/u/5547891?v=4)](https://github.com/erlangsec "erlangsec (1 commits)")[![joelharkes](https://avatars.githubusercontent.com/u/2960938?v=4)](https://github.com/joelharkes "joelharkes (1 commits)")[![DRoet](https://avatars.githubusercontent.com/u/7842510?v=4)](https://github.com/DRoet "DRoet (1 commits)")

---

Tags

email-parseremail-readermail-parsermailmimeparsermime-parserphpphp-imapparsermailmimeemailmailparseMimeMailParserphp-imapmimeparse

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/zbateson-mail-mime-parser/health.svg)

```
[![Health](https://phpackages.com/badges/zbateson-mail-mime-parser/health.svg)](https://phpackages.com/packages/zbateson-mail-mime-parser)
```

###  Alternatives

[php-mime-mail-parser/php-mime-mail-parser

A fully tested email parser for PHP 8.0+ (mailparse extension wrapper).

9979.6M27](/packages/php-mime-mail-parser-php-mime-mail-parser)[zbateson/stream-decorators

PHP psr7 stream decorators for mime message part streams

4748.6M6](/packages/zbateson-stream-decorators)[omnimail/omnimail

PHP Library to send email across all platforms using one interface.

32934.3k](/packages/omnimail-omnimail)[bashkarev/email

Faster MIME Mail Parser could be used to parse emails in MIME format.

208.8k](/packages/bashkarev-email)[vaibhavpandeyvpz/phemail

A pure PHP MIME parser for parsing raw email files (.eml) with full support for multipart messages, nested structures, and RFC 2046 compliance.

33121.7k1](/packages/vaibhavpandeyvpz-phemail)[thefox/smtpd

SMTP server (library) written in pure PHP.

1302.4k1](/packages/thefox-smtpd)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
