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

Sumit picture Sumit · Mar 11, 2012 · Viewed 116.4k times · Source

I am trying to access my gmail account through my localhost. However, I am getting the response:

Fatal error: Call to undefined function imap_open()

This is my code:

$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = '[email protected]';
$password = 'mypassword';

/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' .imap_last_error());

Answer

Lekensteyn picture Lekensteyn · Mar 11, 2012

Simple enough, the IMAP extension is not activated in your PHP installation. It is not enabled by default. If your local installation is running XAMPP on Windows, you have to enable it as described in the XAMPP FAQ:

Where is the IMAP support for PHP?

As default, the IMAP support for PHP is deactivated in XAMPP, because there were some mysterious initialization errors with some home versions like Windows 98. Who works with NT systems, can open the file "\xampp\php\php.ini" to active the php exstension by removing the beginning semicolon at the line ";extension=php_imap.dll". Should be: extension=php_imap.dll

Now restart Apache and IMAP should work. You can use the same steps for every extension, which is not enabled in the default configuration.