Call to undefined function imap_open()

I’m trying to IMAP working on my Mac running Big Sur.

I used HomeBrew to install PHP 8.1:

brew tap shivammathur/php
brew tap shivammathur/extensions
brew install [email protected]

PHP is working and according to the phpinfo() it’s using the correct path.
There’s also the additional path to the imap.ini
The path in the imap.ini exists and there is a imap.so

When i run “php -m” imap is mentioned in the list.

But when I run my code I get the error:

Call to undefined function imap_open()

I tried reinstalling the php with extensions and I tried https://stackoverflow.com/a/66047249/909723 but no success

Hope someone can help!

Thanks in advance