Exception when attempting to process bounced email and monitored email box

Your software
My Mautic version is: 2.16
My PHP version is: 7.3

Your problem
My problem is: Exception when attempting to process bounced email and monitored email box

These errors are showing in the log:[Symfony\Component\Debug\Exception\UndefinedFunctionException]
Attempted to call function “imap_search” from namespace “Mautic\EmailBundle\MonitoredEmail”.

[2020-03-03 23:26:39] mautic.NOTICE: Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined function Mautic\EmailBundle\MonitoredEmail\imap_search() (uncaught exception) at Mautic/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php line 570 while running console command mautic:email:fetch

Steps I have tried to fix the problem: verified email credentials and cleared cache

Cron Error Output: [Symfony\Component\Debug\Exception\UndefinedFunctionException]
Attempted to call function “imap_search” from namespace “Mautic\EmailBundle\MonitoredEmail”.

mautic:email:fetch [-m|–message-limit [MESSAGE-LIMIT]] [-h|–help] [-q|–quiet] [-v|vv|vvv|–verbose] [-V|–version] [–ansi] [–no-ansi] [-n|–no-interaction] [-s|–shell] [–process-isolation] [-e|–env ENV] [–no-debug] [–]

More Debug Info-
app/console mautic:emails:fetch --env=prod -vvv

[Symfony\Component\Debug\Exception\UndefinedFunctionException]
Attempted to call function “imap_search” from namespace “Mautic\EmailBundle\MonitoredEmail”.

Exception trace:
() at /var/www/vhosts/mautic-install/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php:570
Mautic\EmailBundle\MonitoredEmail\Mailbox->searchMailbox() at /var/www/vhosts/mautic-install/app/bundles/EmailBundle/MonitoredEmail/Fetcher.php:107

Mautic\EmailBundle\MonitoredEmail\Fetcher->fetch() at /var/www/vhosts/mautic-install/app/bundles/EmailBundle/Command/ProcessFetchEmailCommand.php:87

Mautic\EmailBundle\Command\ProcessFetchEmailCommand->execute() at /var/www/vhosts/mautic-install/vendor/symfony/console/Command/Command.php:242

Symfony\Component\Console\Command\Command->run() at /var/www/vhosts/mautic-install/vendor/symfony/console/Application.php:861

Symfony\Component\Console\Application->doRunCommand() at /var/www/vhosts/mautic-install/vendor/symfony/console/Application.php:193

Symfony\Component\Console\Application->doRun() at /var/www/vhosts/mautic-install/vendor/symfony/framework-bundle/Console/Application.php:84

Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/vhosts/mautic-install/vendor/symfony/console/Application.php:117

Symfony\Component\Console\Application->run() at /var/www/vhosts/mautic-install/app/console:41

Do you have the php-imap PHP module installed?
Run the command rpm -qa | grep php (CentOS) or dpkg -l | grep php (Ubuntu) and see if it is listed.

If not, try installing it through the package manager
sudo apt install php-imap (CentOS) or sudo yum install php-imap (Ubuntu)
then restart your web server and the PHP-FPM process (if using PHP-FPM).

Apache: sudo systemctl restart httpd (CentOS)
or sudo systemctl restart apache2 (Ubuntu)
Nginx: sudo systemctl restart nginx
PHP-FPM: sudo systemctl restart php-fpm

PHP Warning: imap_body(): supplied resource is not a valid imap resource in /var/www/vhosts-/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php on line 965
PHP Notice: Trying to get property ‘encoding’ of non-object in /var/www/vhosts/-/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php on line 968
PHP Notice: Trying to get property ‘encoding’ of non-object in /var/www/vhosts/-/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php on line 970
PHP Notice: Trying to get property ‘encoding’ of non-object in /var/www/vhosts/-/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php on line 972
PHP Notice: Trying to get property ‘encoding’ of non-object in /var/www/vhosts/-/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php on line 974
PHP Notice: Trying to get property ‘ifid’ of non-object in /var/www/vhosts/-/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php on line 981

imap_fetchheader(): Bad message number in /var/www/vhosts/mautic/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php on line 869
PHP Notice: Undefined property: stdClass::$from in /var/www/vhosts/mautic/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php on line 878
PHP Notice: Trying to get property ‘mailbox’ of non-object in /var/www/vhosts/mautic/app/bundles/EmailBundle/MonitoredEmail/Mailbox.php on line 878

php-imap-5.4.16-9.el7.x86_64 is installed

5.4 is not supported anymore by Mautic.
You need to upgrade PHP and its modules to PHP 7.2 or 7.3.

I had the same issue, the problem is that the console could use a different folder or instance of PHP.

For instance, my mautic folder-project worked with PHP 7.2, but when I was in the console, the active PHP was 7.4 and this version of php did not have the imap library.

I just installed the imap library in php 7.4 and it works!

php -v in the console to see the active php could works

I also got the same problem with EJL, anyone knows how to fix that?
my email monitor login test was successful but I can’t fetch them on a cronjob

I am now experiencing this issue,

I have php 8 IMAP working, it shows in the system info tab as enabled,

Any ideas on how I could trace this issue?

In Mailbox.php line 542:
                                                                                                
  [Symfony\Component\ErrorHandler\Error\UndefinedFunctionError]                                 
  Attempted to call function "imap_search" from namespace "Mautic\EmailBundle\MonitoredEmail".  

[REDACTED]

php8 is not supported yet … need to be at php 7.4

I’m on 4.4 which release PHP 8 support, but either way, I upgraded to 8 to try to remedy the issue but it didn’t work, it started just the same at 7.4

I don’t remember about 4.4 supporting php8 then …

You could be right however I been seeing posts in here recommending to stay with 7.4 until Mautic 5 is released.

Here is that release

The issue still is not that one however, as PHP version does not fix the issue, now only seeing it with

 php /home/crm.grou.com/public_html/bin/console mautic:email:fetch -v