I developed a simple code, with the php language, to connect to my email and count the number of emails received, using the local Window 10 server.
<?php
// server IMAP per la connessione
$server = "{imap.gmail.com:993/ssl/novalidate-cert}";
// account Gmail
$login = '[email protected]';
// password per l'accesso a Gmail
$password = 'password';
// connessione IMAP ad un account Gmail
$connessione = imap_open($server, $login, $password);
$conteggio = imap_num_msg($connessione);
echo $conteggio."<br>";
By enabling the IMAP protocol on Gmail and enabling access to less secure apps, the code does
not give any kind of error.
The problem arises when I try to execute this code into a Centos 7 server machine.
I installed the IMAP protocol compatible with my PHP 7.3 version, using this command line: yum --enablerepo=centos-sclo-sclo-testing install sclo-php73-php-imapservice imapd restart.
Once the package is successfully downloaded, I restart the server machine and go check on
<?php
phpinfo();
?>
and notice that the IMAP is enabled.
imap
IMAP c-Client Version 2007f
SSL Support enabled
Kerberos Support enabled
After this check, if I try to run my initial code, this error message appears to me on output: warning: imap_open(): couldn’t open stream {imap.gmail.com:993/ssl/novalidate-cert} even though i have enabled imap and by actvaing.
PS. the password and login are correct.