PHPackages                             rsaccani/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. rsaccani/mail-mime-parser

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

rsaccani/mail-mime-parser
=========================

MIME email message parser

2.4.0(2y ago)17.7kBSD-2-ClausePHPPHP &gt;=7.1

Since Jul 9Pushed 2y ago2 watchersCompare

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

READMEChangelog (8)Dependencies (8)Versions (12)Used By (0)

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)[![Code Coverage](https://camo.githubusercontent.com/33d6cb411cff4092c55b89deeb4dc39d505d85d065653c3d83521fab550358e2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a62617465736f6e2f6d61696c2d6d696d652d7061727365722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/zbateson/mail-mime-parser/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/af6ea24465aed553c24c6bcafec55b4961b3797d0b3003e781536ed352275245/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a62617465736f6e2f6d61696c2d6d696d652d7061727365722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/zbateson/mail-mime-parser/?branch=master)[![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).

Php 5.4-7.0 Support Dropped
---------------------------

[](#php-54-70-support-dropped)

As of mail-mime-parser 2.3.0, support for php 5.4, 5.5, 5.6 and 7.0 has been dropped.

Removal Notice (since 2.0.0)
----------------------------

[](#removal-notice-since-200)

`getContentResourceHandle`, `getTextResourceHandle`, and `getHtmlResourceHandle` have all been deprecated in 1.2.1 and removed in 2.0.0. fread() will only return a single byte of a multibyte char, and so will cause potentially unexpected results/warnings in some cases, and psr7 streams should be used instead. Note that `getBinaryContentResourceHandle` and `getResourceHandle` are still available.

Change in 2.0
-------------

[](#change-in-20)

Upgrade to 2.0 to take advantage of the new on-demand parser which parses parts of a message as they're requested. This means reading only the headers from a larger message is as fast as a smaller message because the whole message is no longer parsed (similarly reading just the content and not a message's large attachments is also much faster.)

Because of the on-demand parsing, starting in 2.0, the passed resource handle or stream must remain open while the returned message object is still in use.

Old code:

```
$handle = fopen('file.mime', 'r');
$message = $mailParser->parse($handle);         // returned `Message`
fclose($handle);
```

New code:

```
// attaches the resource handle to the returned `IMessage` if the second parameter
// is true.  The resource handle is closed when the IMessage is destroyed.
$message = $mailParser->parse(fopen('file.mime', 'r'), true);
```

For a more complete list of changes, please visit the [2.0 Upgrade Guide](https://mail-mime-parser.org/upgrade-2.0).

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

[](#requirements)

MailMimeParser requires PHP 7.1 or newer. Tested on PHP 7.1, 7.2, 7.3, 7.4, 8.0, 8.1 and 8.2.

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->getHeaderValue(HeaderConsts::SUBJECT);  // 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
    '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);
```

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

[](#documentation)

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

Upgrading to 1.x or 2.x
-----------------------

[](#upgrading-to-1x-or-2x)

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

License
-------

[](#license)

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

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 87.9% 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 ~247 days

Recently: every ~371 days

Total

9

Last Release

897d ago

Major Versions

0.1.5 → 1.0.02019-12-20

1.0.1 → 2.4.02024-01-08

PHP version history (2 changes)0.1.0PHP &gt;=5.4

2.4.0PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2815664?v=4)[Andrea Ruggiero](/maintainers/pupaxxo)[@pupaxxo](https://github.com/pupaxxo)

![](https://avatars.githubusercontent.com/u/6411594?v=4)[Rodolfo Saccani](/maintainers/rsaccani)[@rsaccani](https://github.com/rsaccani)

---

Top Contributors

[![zbateson](https://avatars.githubusercontent.com/u/8356974?v=4)](https://github.com/zbateson "zbateson (715 commits)")[![ThomasLandauer](https://avatars.githubusercontent.com/u/1054469?v=4)](https://github.com/ThomasLandauer "ThomasLandauer (28 commits)")[![phpfui](https://avatars.githubusercontent.com/u/7434059?v=4)](https://github.com/phpfui "phpfui (27 commits)")[![shotap](https://avatars.githubusercontent.com/u/4605350?v=4)](https://github.com/shotap "shotap (10 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)")[![pupaxxo](https://avatars.githubusercontent.com/u/2815664?v=4)](https://github.com/pupaxxo "pupaxxo (3 commits)")[![pableu](https://avatars.githubusercontent.com/u/305859?v=4)](https://github.com/pableu "pableu (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)")[![krisbuist](https://avatars.githubusercontent.com/u/1199343?v=4)](https://github.com/krisbuist "krisbuist (1 commits)")[![jszaszi](https://avatars.githubusercontent.com/u/22881826?v=4)](https://github.com/jszaszi "jszaszi (1 commits)")[![Josh-G](https://avatars.githubusercontent.com/u/487384?v=4)](https://github.com/Josh-G "Josh-G (1 commits)")[![joelharkes](https://avatars.githubusercontent.com/u/2960938?v=4)](https://github.com/joelharkes "joelharkes (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)")

---

Tags

parsermailmimeemailmailparseMimeMailParserphp-imapmimeparse

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[zbateson/mail-mime-parser

MIME email message parser

54551.9M86](/packages/zbateson-mail-mime-parser)[php-mime-mail-parser/php-mime-mail-parser

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

99310.1M35](/packages/php-mime-mail-parser-php-mime-mail-parser)[zbateson/stream-decorators

PHP psr7 stream decorators for mime message part streams

4751.2M7](/packages/zbateson-stream-decorators)[bashkarev/email

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

208.9k](/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.

33127.2k2](/packages/vaibhavpandeyvpz-phemail)[oat-sa/tao-core

TAO core extension

66140.1k108](/packages/oat-sa-tao-core)

PHPackages © 2026

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