How to enable imap module in PHP

–> Recompile php with ‘–with-imap –with-imap-ssl ‘ option in ./configure command.

–> If imap is installed in /usr it will recompile fine.

–> If imap is not installed, we need to install imap lib files first in a location and specify the option in php compilation as ‘–with-imap-ssl=/path/to/imap’.

If the php compilation shows error as follows, do the below steps.

checking whether IMAP works… no

Install custom openssl

cd /usr/src
tar -zxf openssl-0.9.8l.tar.gz
cd  openssl-0.9.8l
./config –prefix=/usr/local/newopenssl
make test
make install

check if installed fine

root@server [/]# /usr/local/newopenssl/bin/openssl version
OpenSSL 0.9.8l 5 Nov 2009

Install imap on a separate location.

download imap.tar.gz
tar -zxvf imap.tar.gz
cp -rp imap-2007f /usr/local/newimap
cd /usr/local/newimap
make slx
mkdir include
ln -s c-client include
mkdir lib
cd lib
ln -s ../c-client/c-client.a libc-client.a

Now recompile php with imap configuration options as follows

–with-imap=/usr/local/newimap –with-imap-ssl=/usr/local/newopenssl

If you still see error, remove the installed imap and imap-devel rpm using yum IMP !! When you do this make sure only these packages are removed and no other packages are removed aling with this. If that is the case press “no” for the yum remove command. You will need to correct the imap error by by yourself then.

yum remove imap imap-devel

Run the php configuration script now.

Imap check php script. Create an email ID and check as follows. Make this php script in the domain documentroot and take in the browser. You will see the email inbox details.


$mail_server = “server_hostname” ;
$mail_port = 143 ;
$mail_username = “” ;
$mail_password = “email_password” ;

echo “<h1>”.$mail_username.” on “.$mail_server.”</h1>\n\n” ;
$mbox = imap_open(“{“.$mail_server.”:”.$mail_port.”}”.$mail_folder, $mail_username, $mail_password) or die(“Error opening mailbox: “.imap_last_error());
$mailboxheaders = imap_headers($mbox);
if ($mailboxheaders == false) {
echo “<p>”.$mail_folder.” is empty.</p>\n\n”;
} else {
echo “<h2>”.$mail_folder.”</h2>\n” ;
echo “<ol>\n” ;
$msgno = 0;
foreach ($mailboxheaders as $val) {
echo ”  <li>”.$val .”</li>\n”;
echo “</ol>\n\n” ;


  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: