PHPackages                             forked/mailreader - 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. forked/mailreader

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

forked/mailreader
=================

A fully tested simple email reader parser for PHP 5.6+.

1.0.1(6y ago)64.5k—0%51LGPL-3.0-or-laterPHPPHP &gt;5.6

Since Jul 10Pushed 6y ago1 watchersCompare

[ Source](https://github.com/techno-express/mailreader)[ Packagist](https://packagist.org/packages/forked/mailreader)[ Docs](https://github.com/techno-express/mailreader)[ RSS](/packages/forked-mailreader/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (1)

mailreader
==========

[](#mailreader)

[![Build Status](https://camo.githubusercontent.com/b3e273978992384c49af9242a62e5ebd7602274d1b22cb666a0633e5f2a70ed9/68747470733a2f2f7472617669732d63692e6f72672f746563686e6f2d657870726573732f6d61696c7265616465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/techno-express/mailreader)[![Build status](https://camo.githubusercontent.com/8b02ae4bb6d5d84898fa97240a2a8192f3a2eff72ff12126c04efe87ca766152/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f776778686a71646771733138397871762f6272616e63682f6d61737465723f7376673d74727565)](https://ci.appveyor.com/project/techno-express/mailreader/branch/master)[![codecov](https://camo.githubusercontent.com/831bc88122d2af2b87424bfd28b318bd88a2b90a55fa478f84cfcf4bf970464a/68747470733a2f2f636f6465636f762e696f2f67682f746563686e6f2d657870726573732f6d61696c7265616465722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/techno-express/mailreader)[![Codacy Badge](https://camo.githubusercontent.com/0c37ef03498b5e1caca6ce56d4e956ff2de27e13a6933689cdeb92702d17bcc3/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3734336336656139646639303439336639626235366466386534323764666538)](https://www.codacy.com/manual/techno-express/mailreader?utm_source=github.com&utm_medium=referral&utm_content=techno-express/mailreader&utm_campaign=Badge_Grade)[![Maintainability](https://camo.githubusercontent.com/9c6631c47ae172b63ab2a35349d09b4b051fb1e47674355fb15c6c90e0552ca5/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f64353534333937303161653239613262626162362f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/techno-express/mailreader/maintainability)

Receive mail and attachments with PHP

This package can be used to...

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

Usage
-----

[](#usage)

Full documentation is a work in progress, see **Phpunit** [tests](#./tests/) folder for more example usage.

**MailReader.php** contains the class that works with the incoming email, and the database.

**MailParser.php** contains the class that works with any file that's in an email format.

**mailPipe.php** is a sample script using the MailReader class.

**mailPipe.php** expects to receive raw emails via **STDIN**.

You can run the script manually by using **`cat`**

```
cat tests/testfile | ./mailPipe.php
```

Or **`type`** On Windows

```
type tests\testfile | php mailPipe.php
```

You will likely want to copy *mailPipe.php* to your own script and adjust the parameters to suite your needs.

This library also allows you to easily parse an email given its content (headers + body).

```
require 'vendor/autoload.php';

use Mail\MailParser;

$emailPath = "/var/mail/spool/dan/new/12323344323234234234";
$emailParser = new MailParser(file_get_contents($emailPath));

// You can use some predefined methods to retrieve headers...
$to = $emailParser->getTo();
$subject = $emailParser->getSubject();
$cc = $emailParser->getCc();
$from = $emailParser->getFrom();
$fromName = $emailParser->getFromName();
$fromEmail = $emailParser->getFromEmail();
$attachments = $emailParser->getAttachments();

$actualContent = $attachments[0]['content']

// ... or you can use the 'general purpose' method getHeader()
$emailDeliveredToHeader = $emailParser->getHeader('Delivered-To');

$emailBody = $emailParser->getPlain();
```

Installation
------------

[](#installation)

```
composer require forked/mailreader
```

Will pull composer [forked/mail\_mime-decode](https://packagist.org/packages/forked/mail_mime-decode) package in as dependency.

Setup
-----

[](#setup)

Configure your mail server to pipe emails to this script. See for instructions.

Make this script *executable*, and edit the configuration options to suit your needs. Change permissions of the directories so that the user executing the script (probably the mail user) will have write permission to the file upload directory.

By default the script is configured to save pdf, zip, jpg, png and gif files. Edit the method array property `$allowed_mime_types` around line 47 to change this. Or call `->addMimeType()` to add more.

***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 mailPipe.php)

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

Edit this line (register myhook)

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

License
-------

[](#license)

Copyright 2012, Michael Moore

Licensed under the same terms as PHP itself and under the GPLv2 or Later. You are free to use this script for personal or commercial projects. Use at your own risk. No guarantees or warranties.

Support
-------

[](#support)

1. If you have problems, you are encouraged to post them on the MailReader GitHub issue tracker instead of as comments on my blog.
2. MailReader is OpenSource. You can pay (or not) anyone you want (including yourself!) to work on MailReader, the code is here.
3. I will accept GitHub pull requests that fix bugs or add features. This sort of maintenance will be done for free.

Thanks
------

[](#thanks)

Many thanks to *forahobby* of [www.360-hq.com](http://www.360-hq.com) for testing this script and helping me find the initial bugs and *Craig Hopson* of twitterrooms.co.uk for help tracking down an iOS email handling bug.

Versions
--------

[](#versions)

***July 9, 2019***

- many additions, library more **OOP** compliant.
- added methods to easily retrieved records from the database.
- added additional classes to work with any email formated file/folder.
- added PSR-4 support, can now be installed using [Composer](https://getcomposer.org).
- added phpunit tests, and email files to test against.
- removed allowed senders, any email received with script will get an reply if turned on.
- the mailPipe script now setup to auto locate the database config and create database if not initialized.
- general code clean up.

***May 21, 2013***

- UUEncoded attachment support
- It's now a class
- Uses PHP PDO connection with prepared statements instead of mysql/mysql\_real\_escape\_string
- Support for inline content type (from mail app on mac?)

***April 14, 2012***

- Uses PEAR's mimeDecode.php
- Support for more mime part configurations

***March 24, 2010***

- Initial release
- Works for me, for gmail.com
- Homemade parser!

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~125 days

Total

2

Last Release

2378d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1a9d88c23f07f785e0358746ae2384950a6f8dac0c3bd4fbbc910e94f7eb637?d=identicon)[techno-express](/maintainers/techno-express)

---

Top Contributors

[![TheTechsTech](https://avatars.githubusercontent.com/u/29784725?v=4)](https://github.com/TheTechsTech "TheTechsTech (23 commits)")[![stuporglue](https://avatars.githubusercontent.com/u/16576?v=4)](https://github.com/stuporglue "stuporglue (21 commits)")[![adhayward](https://avatars.githubusercontent.com/u/18305551?v=4)](https://github.com/adhayward "adhayward (1 commits)")[![demukti](https://avatars.githubusercontent.com/u/3626063?v=4)](https://github.com/demukti "demukti (1 commits)")[![designosis](https://avatars.githubusercontent.com/u/146623?v=4)](https://github.com/designosis "designosis (1 commits)")

---

Tags

email-parsingmailmimemime-decodingmime-parserphpparseremaildecodereaderpipe

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/forked-mailreader/health.svg)

```
[![Health](https://phpackages.com/badges/forked-mailreader/health.svg)](https://phpackages.com/packages/forked-mailreader)
```

###  Alternatives

[egulias/email-validator

A library for validating emails against several RFCs

11.6k691.3M307](/packages/egulias-email-validator)[zbateson/mail-mime-parser

MIME email message parser

54149.2M79](/packages/zbateson-mail-mime-parser)[sendgrid/sendgrid

This library allows you to quickly and easily send emails through Twilio SendGrid using PHP.

1.5k47.5M164](/packages/sendgrid-sendgrid)[pelago/emogrifier

Converts CSS styles into inline style attributes in your HTML code

94944.1M110](/packages/pelago-emogrifier)[soundasleep/html2text

A PHP script to convert HTML into a plain text format

48519.5M75](/packages/soundasleep-html2text)[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)

PHPackages © 2026

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