Make sure you have the mailparse extension (http://php.net/manual/en/book.mailparse.php) properly installed. The command line `php -m | grep mailparse` need to return "mailparse" else install it:
* PHP version > 7.0: mailparse
* PHP version <7.0:mailparse2.1.6
Follow this steps to install mailparse:
* Compile in the temp folder the extension mailparse or mailparse-2.1.6 (workaround because pecl install doesn't work yet)
```
cd
pecl download mailparse
tar -xvf mailparse-3.0.2.tgz
cd mailparse-3.0.2/
phpize
./configure
sed -i 's/#if\s!HAVE_MBSTRING/#ifndef MBFL_MBFILTER_H/' ./mailparse.c
echo "extension=mailparse.so" | sudo tee /etc/php/7.1/mods-available/mailparse.ini
sudo phpenmod mailparse
```
On Windows, you need to download mailparse DLL from http://pecl.php.net/package/mailparse and add the line "extension=php_mailparse.dll" to php.ini accordingly.
## How do I use it?
```php
<?php
// Include the library first
require_once __DIR__.'/vendor/autoload.php';
$path = 'path/to/mail.txt';
$Parser = new PhpMimeMailParser\Parser();
// There are four methods available to indicate which mime mail to parse.
// You only need to use one of the following four:
// 1. Specify a file path to the mime mail.
$Parser->setPath($path);
// 2. Specify a php file resource (stream) to the mime mail.
$Parser->setStream(fopen($path, "r"));
// 3. Specify the raw mime mail text.
$Parser->setText(file_get_contents($path));
// 4. Specify a stream to work with mail server
$Parser->setStream(fopen("php://stdin", "r"));
// Once we've indicated where to find the mail, we can parse out the data
echo 'MIME part string : '.$attachment->getMimePartStr().'<br/>'; // (the whole MIME part of the attachment)
}
}
?>
```
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)