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

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

benpoulson/php-mime-mail-parser
===============================

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

5.0.0(7y ago)07.3kMITPHPPHP ^7.1

Since Mar 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/benpoulson/php-mime-mail-parser)[ Packagist](https://packagist.org/packages/benpoulson/php-mime-mail-parser)[ Docs](https://github.com/php-mime-mail-parser/php-mime-mail-parser)[ RSS](/packages/benpoulson-php-mime-mail-parser/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (4)Versions (73)Used By (0)

php-mime-mail-parser
====================

[](#php-mime-mail-parser)

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

It's the most effective php email parser around in terms of performance, foreign character encoding, attachment handling, and ease of use. Internet Message Format RFC [822](https://tools.ietf.org/html/rfc822), [2822](https://tools.ietf.org/html/rfc2822), [5322](https://tools.ietf.org/html/rfc5322).

[![Latest Version](https://camo.githubusercontent.com/68ca4ca09d9813fcf8013e38a8085879c250ae50acc00c75d6fad8786f665173/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068702d6d696d652d6d61696c2d7061727365722f7068702d6d696d652d6d61696c2d7061727365722e7376673f7374796c653d666c61742d737175617265)](https://github.com/php-mime-mail-parser/php-mime-mail-parser/releases)[![Total Downloads](https://camo.githubusercontent.com/18f5e5881142545fc96af8c4e00b714ad8c8097b7acbc43dacfb99f7b18ca2fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068702d6d696d652d6d61696c2d7061727365722f7068702d6d696d652d6d61696c2d7061727365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/php-mime-mail-parser/php-mime-mail-parser)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Why?
----

[](#why)

This extension can be used to...

- Parse and read email from Postfix
- For reading messages (Filename extension: eml)
- Create webmail
- Store email information such a subject, HTML body, attachments, and etc. into a database

Is it reliable?
---------------

[](#is-it-reliable)

Yes. All known issues have been reproduced, fixed and tested.

We use Travis CI to help ensure code quality. You can see real-time statistics below:

[![Build Status](https://camo.githubusercontent.com/e39003bb48671d3d870de3a035a408855e586378813fee9ae964827ac8cb7496/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7068702d6d696d652d6d61696c2d7061727365722f7068702d6d696d652d6d61696c2d7061727365722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/php-mime-mail-parser/php-mime-mail-parser)[![Coverage](https://camo.githubusercontent.com/731d3bbd24f67a5c487ef849606ac82646ea4f80291bde7783a00ab57fe528f0/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f7068702d6d696d652d6d61696c2d7061727365722f7068702d6d696d652d6d61696c2d7061727365722e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/php-mime-mail-parser/php-mime-mail-parser)[![Quality Score](https://camo.githubusercontent.com/81a10777fa018bb818fae42fa801fabb4ab8e0d0d57461fc6979e4eba739dde5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7068702d6d696d652d6d61696c2d7061727365722f7068702d6d696d652d6d61696c2d7061727365722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/php-mime-mail-parser/php-mime-mail-parser)

How do I install it?
--------------------

[](#how-do-i-install-it)

The easiest way is via [Composer](https://getcomposer.org/).

To install the latest version of PHP MIME Mail Parser, run the command below:

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

```

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

[](#requirements)

The following versions of PHP are supported:

- PHP 7.1
- PHP 7.2
- PHP 7.3

Previous Versions:

PHP CompatibilityVersionHHVMphp-mime-mail-parser 2.11.1PHP 5.4php-mime-mail-parser 2.11.1PHP 5.5php-mime-mail-parser 2.11.1PHP 5.6php-mime-mail-parser 3.0.4PHP 7.0php-mime-mail-parser 3.0.4Make sure you have the mailparse extension () properly installed. The command line `php -m | grep mailparse` need to return "mailparse".

### Install mailparse extension

[](#install-mailparse-extension)

#### Ubuntu, Debian &amp; derivatives

[](#ubuntu-debian--derivatives)

```
sudo apt install php-cli php-mailparse

```

#### Others platforms

[](#others-platforms)

```
sudo apt install php-cli php-pear php-dev php-mbstring
pecl install mailparse

```

#### From source

[](#from-source)

AAAAMMDD should be `php-config --extension-dir`

```
git clone https://github.com/php/pecl-mail-mailparse.git
cd pecl-mail-mailparse
phpize
./configure
sed -i 's/#if\s!HAVE_MBSTRING/#ifndef MBFL_MBFILTER_H/' ./mailparse.c
make
sudo mv modules/mailparse.so /usr/lib/php/AAAAMMDD/
echo "extension=mailparse.so" | sudo tee /etc/php/7.1/mods-available/mailparse.ini
sudo phpenmod mailparse

```

#### Windows

[](#windows)

You need to download mailparse DLL from  and add the line "extension=php\_mailparse.dll" to php.ini accordingly.

How do I use it?
----------------

[](#how-do-i-use-it)

### Loading an email

[](#loading-an-email)

You can load an email with 4 differents ways. You only need to use one of the following four.

```
require_once __DIR__.'/vendor/autoload.php';

$path = 'path/to/email.eml';
$parser = new PhpMimeMailParser\Parser();

// 1. Specify a file path (string)
$parser->setPath($path);

// 2. Specify the raw mime mail text (string)
$parser->setText(file_get_contents($path));

// 3. Specify a php file resource (stream)
$parser->setStream(fopen($path, "r"));

// 4.  Specify a stream to work with mail server (stream)
$parser->setStream(fopen("php://stdin", "r"));
```

### Get the metadata of the message

[](#get-the-metadata-of-the-message)

Get the sender and the receiver:

```
$rawHeaderTo = $parser->getHeader('to');
// return "test" , "test2"

$arrayHeaderTo = $parser->getAddresses('to');
// return [["display"=>"test", "address"=>"test@example.com", false]]

$rawHeaderFrom = $parser->getHeader('from');
// return "test"

$arrayHeaderFrom = $parser->getAddresses('from');
// return [["display"=>"test", "address"=>"test@example.com", "is_group"=>false]]
```

Get the subject:

```
$subject = $parser->getHeader('subject');
```

Get other headers:

```
$stringHeaders = $parser->getHeadersRaw();
// return all headers as a string, no charset conversion

$arrayHeaders = $parser->getHeaders();
// return all headers as an array, with charset conversion
```

### Get the body of the message

[](#get-the-body-of-the-message)

```
$text = $parser->getMessageBody('text');
// return the text version

$html = $parser->getMessageBody('html');
// return the html version

$htmlEmbedded = $parser->getMessageBody('htmlEmbedded');
// return the html version with the embedded contents like images
```

### Get attachments

[](#get-attachments)

Save all attachments in a directory

```
$parser->saveAttachments('/path/to/save/attachments/');
// return all attachments saved in the directory (include inline attachments)

$parser->saveAttachments('/path/to/save/attachments/', false);
// return all attachments saved in the directory (exclude inline attachments)
```

Get all attachments

```
$attachments = $parser->getAttachments();
// return an array of all attachments (include inline attachments)

$attachments = $parser->getAttachments(false);
// return an array of all attachments (exclude inline attachments)
```

Loop through all the Attachments

```
foreach ($attachments as $attachment) {
    echo 'Filename : '.$attachment->getFilename().'';
    // return logo.jpg

    echo 'Filesize : '.filesize($attach_dir.$attachment->getFilename()).'';
    // return 1000

    echo 'Filetype : '.$attachment->getContentType().'';
    // return image/jpeg

    echo 'MIME part string : '.$attachment->getMimePartStr().'';
    // return the whole MIME part of the attachment
}
```

Postfix configuration to manage email from a mail server
--------------------------------------------------------

[](#postfix-configuration-to-manage-email-from-a-mail-server)

Next you need to forward emails to this script above. For that I'm using [Postfix](http://www.postfix.org/) like a mail server, you need to configure /etc/postfix/master.cf

Add this line at the end of the file (specify myhook to send all emails to the script test.php)

```
myhook unix - n n - - pipe
  				flags=F user=www-data argv=php -c /etc/php5/apache2/php.ini -f /var/www/test.php ${sender} ${size} ${recipient}

```

Edit this line (register myhook)

```
smtp      inet  n       -       -       -       -       smtpd
        			-o content_filter=myhook:dummy

```

The php script must use the fourth method to work with this configuration.

And finally the easiest way is to use my SaaS

Can I contribute?
-----------------

[](#can-i-contribute)

Feel free to contribute!

```
git clone https://github.com/php-mime-mail-parser/php-mime-mail-parser
cd php-mime-mail-parser
composer install
./vendor/bin/phpunit

```

If you report an issue, please provide the raw email that triggered it. This helps us reproduce the issue and fix it more quickly.

License
-------

[](#license)

The php-mime-mail-parser/php-mime-mail-parser is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 76.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 ~28 days

Recently: every ~9 days

Total

66

Last Release

2570d ago

Major Versions

1.7.4 → 2.0.02015-04-26

2.11.1 → 3.0.02018-07-23

3.0.3 → 4.0.02019-03-17

3.0.4 → 4.0.12019-03-19

4.0.3 → 5.0.02019-04-25

PHP version history (5 changes)v1.0.0PHP &gt;=5.3.0

2.0.0PHP &gt;=5.4.0

2.2.3PHP ^5.4.0 || ^7.0

3.0.0PHP ^5.6.0 || ^7.0

4.0.0PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/85d93938cbda24f3ae1b325d2c1ac89e95f1f845365395a693bad51e8b61b5d9?d=identicon)[BenPoulson](/maintainers/BenPoulson)

---

Top Contributors

[![eXorus](https://avatars.githubusercontent.com/u/1255561?v=4)](https://github.com/eXorus "eXorus (346 commits)")[![fkoyer](https://avatars.githubusercontent.com/u/8293789?v=4)](https://github.com/fkoyer "fkoyer (21 commits)")[![iateadonut](https://avatars.githubusercontent.com/u/1443928?v=4)](https://github.com/iateadonut "iateadonut (11 commits)")[![hadyhallak](https://avatars.githubusercontent.com/u/5484006?v=4)](https://github.com/hadyhallak "hadyhallak (9 commits)")[![VincentDauce](https://avatars.githubusercontent.com/u/18286949?v=4)](https://github.com/VincentDauce "VincentDauce (7 commits)")[![fijiwebdesign](https://avatars.githubusercontent.com/u/809011?v=4)](https://github.com/fijiwebdesign "fijiwebdesign (7 commits)")[![xqus](https://avatars.githubusercontent.com/u/203013?v=4)](https://github.com/xqus "xqus (6 commits)")[![gmta](https://avatars.githubusercontent.com/u/3210731?v=4)](https://github.com/gmta "gmta (5 commits)")[![lucasvdh](https://avatars.githubusercontent.com/u/4311594?v=4)](https://github.com/lucasvdh "lucasvdh (4 commits)")[![ThibaudDauce](https://avatars.githubusercontent.com/u/1770543?v=4)](https://github.com/ThibaudDauce "ThibaudDauce (4 commits)")[![myselfhimself](https://avatars.githubusercontent.com/u/1265346?v=4)](https://github.com/myselfhimself "myselfhimself (3 commits)")[![uda](https://avatars.githubusercontent.com/u/199314?v=4)](https://github.com/uda "uda (3 commits)")[![luiz-brandao](https://avatars.githubusercontent.com/u/704231?v=4)](https://github.com/luiz-brandao "luiz-brandao (3 commits)")[![dorianfm](https://avatars.githubusercontent.com/u/274287?v=4)](https://github.com/dorianfm "dorianfm (3 commits)")[![AntoineAugusti](https://avatars.githubusercontent.com/u/295709?v=4)](https://github.com/AntoineAugusti "AntoineAugusti (2 commits)")[![benpoulson](https://avatars.githubusercontent.com/u/1797843?v=4)](https://github.com/benpoulson "benpoulson (2 commits)")[![designosis](https://avatars.githubusercontent.com/u/146623?v=4)](https://github.com/designosis "designosis (2 commits)")[![duncan3dc](https://avatars.githubusercontent.com/u/546811?v=4)](https://github.com/duncan3dc "duncan3dc (2 commits)")[![eryno](https://avatars.githubusercontent.com/u/691315?v=4)](https://github.com/eryno "eryno (2 commits)")[![odknt](https://avatars.githubusercontent.com/u/4185305?v=4)](https://github.com/odknt "odknt (2 commits)")

---

Tags

phpparsermailmimemailparseMimeMailParser

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/benpoulson-php-mime-mail-parser/health.svg)](https://phpackages.com/packages/benpoulson-php-mime-mail-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/mail-mime-parser

MIME email message parser

53949.2M79](/packages/zbateson-mail-mime-parser)[bashkarev/email

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

208.8k](/packages/bashkarev-email)[henrique-borba/php-sieve-manager

A modern (started in 2022) PHP library for the ManageSieve protocol (RFC5804) to create/edit Sieve scripts (RFC5228). Used by Cypht Webmail.

23125.7k2](/packages/henrique-borba-php-sieve-manager)

PHPackages © 2026

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