Call to undefined function imap_open() on a dedicated server

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 and put this:

<?php phpinfo(); ?>

Run it in the browser and search for imap.ini in ‘additional .ini files parsed‘ if it is not there, so it means that PHP is not listening to IMAP module, so 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 uncomment, and now open your fav text editor and write that above line in it, save the above file as imap.ini and now 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, you are done.

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 the similar steps on another distro.