To make IMAP working with PHP we need to install these modules, install these from synaptic package manager.

  • php-imap
  • php-cli

Now in case IMAP is not working, create a file named info.php with:

<?php phpinfo(); ?>

Run it in the browser and search for imap.ini in additional .ini files parsed if it is not there, it means that PHP is not listening to IMAP module. We need to enable/use extension for imap. At the mean time search php.ini for imap. If this is there:

extension = imap.so

Just leave it there as uncommented, and now open your favorite text editor and paste that above line in it, save the file as imap.ini and upload it to this directory: /etc/php5/conf.d and restart the server:

/etc/init.d/apache2 restart

One thing more to note is in info.php to see whether which conf file is loaded by apache, look for this line:

/etc/php5/apache2/php.ini

Now refresh the info.php in the browser and you will see that this line is there in front of additional .ini files parsed.

/etc/php5/apache2/conf.d/imap.ini

And that’s it.

Points to note: The above solution is for the following error. (Mostly running it in cron will throw this error, but if you run your script in browser it will work fine).

Fatal error: Call to undefined function imap_open() in...

This is work around for Ubuntu OS. You can try similar steps on another distro.