9

I'm currently working to put our project under php7.

When trying to compile the mailparse extension or use pecl to install it, I get this error:

#error The mailparse extension requires the mbstring extension!

I did install the php7.0-mbstring and tried to put the mbstring extension with the mailparse source code. I also tried to use my old C skills and try include the libraries myself without success.

Any of you has an idea how I could solve my problem? (without editing the code like I saw in some forums)

Thanks

NikiC
  • 100,734
  • 37
  • 191
  • 225
  • Confirm both `mailparse` and `mbstring` extensions enabled by examining the output of `phpinfo()` – Raptor Mar 04 '16 at 10:13
  • After looking, I can confirm that mbstring is installed and enabled. But since mailparse doesn't get installed cause of the error, it is missing – Charles Teinturier Mar 04 '16 at 10:55

1 Answers1

37

You should be able to download the mailparse source, comment out the test for HAVE_MBSTRING in mailparse.c (around line 34), and build it normally.

Here's what I did in Ubuntu 16.04 (assume 'sudo' when necessary):

cd /tmp

apt-get install php7.0-dev

pecl download mailparse

tar xvzf mailparse-3.0.2.tgz

cd mailparse-3.0.2

phpize

./configure

sed -i \
  's/^\(#error .* the mbstring extension!\)/\/\/\1/' \
  mailparse.c

make

make install

Then you just need to enable the mailparse.so module in your PHP configuration.

For Ubuntu 16.04 and PHP-FPM, you'd use:

echo "extension=mailparse.so" > \
  /etc/php/7.0/fpm/conf.d/30-mailparse.ini

service php7.0-fpm reload
Jeff Standen
  • 6,670
  • 1
  • 17
  • 18
  • I saw your note about "without editing code". I should mention that Zend's own help resources recommend the same fix: https://support.zend.com/hc/en-us/articles/203408233-Compile-mailparse-extension-with-mbstring-dependency- – Jeff Standen Apr 15 '16 at 00:33
  • 3
    I just wanted to add that phpize will not work unless you have installed php7.0-dev (e.g. sudo apt install php7.0-dev) – Kevin Remisoski Sep 13 '16 at 22:04
  • Good call, @KevinRemisoski. Thanks! – Jeff Standen Sep 15 '16 at 07:09
  • 1
    If you are in Ubuntu 16 LTS Its best to create symbolic link `echo "extension=mailparse.so" > \ /etc/php/7.0/mods-available/mailparse.ini` `ln -s /etc/php/7.0/mods-available/mailparse.ini /etc/php/7.0/cli/conf.d/30-mailparse.ini` `ln -s /etc/php/7.0/mods-available/mailparse.ini /etc/php/7.0/cli/conf.d/30-mailparse.ini` – yespbs Dec 28 '17 at 06:51