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.
The mailparse extension does not yet support PHP 7.3 or 7.4.
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.X-sp/conf.d/mailparse.ini" sudo service php7.X-fpm-sp restart
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
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
To uninstall this extension, as root run the commands:
sudo rm /etc/phpX.Y-sp/conf.d/mailparse.ini sudo peclX.Y-sp uninstall mailparse
Next, restart PHP-FPM with the command:
sudo service phpX.Y-fpm-sp restart