Installing PHP Mailparse
If your PHP5 environment doesn't already have the 'mailparse' extension installed then you'll need to add it
- 1 On Unix-based Servers
- 2 On Windows-based Servers (XAMPP)
- 3 On Windows-based Servers (IIS)
- 4 Additional Notes
- 5 External Links
On Unix-based Servers
Generally, installation can be accomplished with a simple command at the server console:
pecl install mailparse
This should retrieve, compile and install the extension. You'll usually need to enable the mailparse extension in your php.ini file by hand. This is accomplished in various ways for different OS/distributions.
In most cases you can simply add the following line to your php.ini:
You may need to edit the pecl script (usually /usr/local/bin/pecl) and remove the ‘-n’ from the command line arguments.
For RHEL 5
RHEL 5 Only supports 5.1.6 you will need to upgrade your php to 5.2+. The older instructions are no longer valid as of 4.3.0.
If your installed version of PHP does not match the system installed version, then these steps can fail with the following error in your PHP log:
PHP Warning: PHP Startup: mailparse: Unable to initialize module Module compiled with module API=[date1], debug=0, thread-safety=0 PHP compiled with module API=[date2, debug=0, thread-safety=0 These options need to match in Unknown on line 0
If you are using SeLinux to protect your system, you will need to change selinux security context of the mailparse.so. PHP will be able to load the extension, but SeLinux will prevent php from using it.
to check the security context: getfattr -n security.selinux /path/to/your/mailparse.so if you don't get something like this security.selinux="system_u:object_r:textrel_shlib_t:s0\000", your must change it. to change the security context: sudo setfattr -n security.selinux -v "system_u:object_r:textrel_shlib_t:s0\000" /path/to/your/mailparse.so
Installing mailparse on RHEL6 based distributions is easy if you enable the EPEL repository.
su -c 'rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm' su -c 'yum install php-pecl-mailparse'
From source code
Contributed by: BlueC (Cerb4 Forums)
Ubuntu (Debian) LAMP-based install
Contributed by: alamb (Cerb4 Forums)
You will need to install the following packages
sudo apt-get install php5-gd php5-imap php-pear php5-dev make php5-mcrypt
Now you can install mailparse
sudo pecl install mailparse
Next edit your php.ini file and add mailparse.so
sudo nano /etc/php5/apache2/conf.d/mailparse.ini
sudo nano /etc/php5/conf.d/mailparse.ini
This will create a new file. Add the line
Mac OS X (XAMPP)
- Download and install the 'Developer Tools' package from http://www.apachefriends.org/en/xampp-macosx.html
- From the console:
sudo /Applications/XAMPP/xamppfiles/bin/pear install pecl/mailparse
On Windows-based Servers (XAMPP)
If you're using XAMPP, or a similar distribution, you probably already have the mailparse extension available. Note that XAMPP 1.71 is the latest version to ship with mailparse.
If you do not have php_mailparse.dll, you can download it from:
- http://downloads.php.net/pierre/ (PHP versions below 5.3)
- http://www.rene-schwarz.com/web/Blog:Personal/php_mailparse.dll_for_PHP_5.3.x (PHP version 5.3.x, build with VC6)
- http://www.rene-schwarz.com/web/Blog:EN/php_mailparse.dll_for_PHP_5.3.6_and_above_%28VC9_version%29_available (PHP version 5.3.x, build with VC9 - standard since PHP 5.3.6)
- Edit your php.ini file (use http://localhost/cerb4/install/phpinfo.php to identify the correct php.ini file, since it is not unusual to have several different ones)
- Remove the ';' in front of the line:
- Save your php.ini file
- Restart Apache
On Windows-based Servers (IIS)
(Contributed by TravisT)
mbstring before mailparse
Also don't forget to load the mbstring extension before you load mailparse.
For example, in the php.ini place in this order:
Or you will get an error.
Contributed by: Mustafa
Contributed by: brwatters
If you get the "checking whether the C compiler works... configure: error: cannot run C compiled programs." error, check the mount permissions on your /tmp directory. You may need to remount /tmp as executable.
# mount | grep /tmp /dev/sda3 on /tmp type ext3 (rw) /tmp on /var/tmp type none (rw,noexec,nosuid,bind) # mount -o remount,exec,suid /tmp
do your compiling, then
# mount -o remount,noexec,nosuid /tmp
Contributed by Alex in Community Town Hall
If you cannot install the Mailparse extension, a member on the forums has written PHP emulation called "mailpars2em" which uses the freely available PEAR package "Mail/mimeDecode" instead of Mailparse. No compilation is required, but since it is not compiled C code, it runs more slowly than Mailparse. You can download mailpars2em, under an "experimental, use at your own risk" agreement. For more information, see this forum thread.
Contributed by Kitchin in Forums