Fatal Error: Call to Undefined Function Imap_Open() in PHP

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

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.

Fatal Error: Call to undefined function imap_open PHP

This should be a comment, but I haven't got the reps for comment, so...

  1. Try to check your extension file, i.e. make sure that in /etc/php5/mods-enabled/imap.ini, the keyword extension=/path/to/imap.so is not commented (having ; or # as its beginning of line) and your /path/to/imap.so file exists.

  2. Try to check if you had multiple php-fpm services running. Use systemctl list-unit-files | grep php to check. If you had multiple php-fpm services, make sure you had installed imap extension to the correct php-fpm instance.

Fatal error: Call to undefined function imap_open()

You can use Zend_Mail to read an imap mailbox with no need for the imap extension since it's a pure php implementation (it uses sockets to connect to a mail server) of the IMAP protocol.

There is no special requirements to use Zend Framework on your host. Just download the package, extract it and upload on your hosting. I suggest you the minimal edition it's ok for running the following code.

In order to connect to a Gmail account you can start with this code, it will connect to your account, get the first message stored on server and output its subject, then you can expand it.

<?
// Ensure Zend folder is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
'/home/tachyon/public_html/zend/library/',
get_include_path(),
)));

// require the ZF autoloader file if you have it in your include path
require_once 'Zend/Loader/Autoloader.php';
// if ZF is not in your path you can specify the full path
// otherwise if it's in a subdir (most likely if you're on a web hosting)
// you can do something like this
//require_once dirname(__FILE__) . '/Zend/Loader/AutoLoader.php';

// laod the autoloader so you don't need to require any ZF file
Zend_Loader_Autoloader::getInstance();

// connecting with Imap to gmail
$mail = new Zend_Mail_Storage_Imap(
array(
'host' => 'imap.gmail.com',
'port' => '993',
'ssl' => true,
'user' => 'user@gmail.com',
'password' => 'secret',
)
);

// get the message object
$message = $mail->getMessage(1);
// output subject of message
echo $message->subject . "\n";
// dump message headers
Zend_Debug::dump($message->getHeaders());

I personally tested this with my Gmail account, so it's working code.



Related Topics



Leave a reply



Submit