https://serverpilot.io/community/articles/how-to-install-the-php-mailparse-extension.html

In the examples shown, replace "X.Y" with your app's PHP version (for example, "5.6" or "7.0". To install this extension for multiple PHP versions, repeat the installation for each PHP version.
The PHP mailparse extension provides functions for parsing and working with email messages. It can deal with RFC 822 and RFC 2045 (MIME) compliant messages. Mailparse is stream-based, meaning it does not keep in-memory copies of the files it processes and so is very resource efficient when dealing with large messages.

Install Mailparse on PHP 7.0, 7.1, or 7.2

To install this extension on PHP 7.X, SSH in to your server as root and run the following commands:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo pecl7.X-sp install --nodeps mailparse
sudo bash -c "echo extension=mailparse.so > /etc/php7.0-sp/conf.d/mailparse.ini"
sudo service php7.X-fpm-sp restart
Install Mailparse on PHP 5.4, 5.5, or 5.6

To install this extension on PHP 5.X, SSH in to your server as root and run the following commands:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo pecl5.X-sp install --nodeps mailparse-2.1.6
sudo bash -c "echo extension=mailparse.so > /etc/php5.X-sp/conf.d/mailparse.ini"
sudo service php5.X-fpm-sp restart
Verify the Installation

You can verify the mailparse extension is installed by running this command:

phpX.Y-sp -i | grep mailparse
You should see output such as the following:

/etc/phpX.Y-sp/conf.d/mailparse.ini,
mailparse
mailparse support => enabled
mailparse.def_charset => us-ascii => us-ascii
Last updated: August 31, 2017

------------------------------
Liquid Layer Networks
http://www.LiquidLayer.net