Z
Z
Zimaell2019-07-10 17:48:35
PHP
Zimaell, 2019-07-10 17:48:35

How to install imap ubuntu php 7.2?

I'm trying to see mail on gmail, they advised such a script

$imap = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', $username, $password);
$emails = imap_search($imap, 'ALL');
if($emails) {  echo count($emails); }
imap_close($inbox);

gave me an error in response
PHP Fatal error:  Uncaught Error: Call to undefined function imap_open()

i.e. library not found or disabled, digging around came across a solution
sudo apt install php-imap
in response
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libc-client2007e mlock php7.3-imap
Suggested packages:
  uw-mailutils
The following NEW packages will be installed:
  libc-client2007e mlock php-imap php7.3-imap
0 upgraded, 4 newly installed, 0 to remove and 30 not upgraded.
Need to get 28.5 kB/622 kB of archives.
After this operation, 1,618 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Err:1 https://packages.sury.org/php stretch/main amd64 php7.3-imap amd64 7.3.5-1+0~20190503093827.38+stretch~1.gbp60a41b
  404  Not Found
E: Failed to fetch https://packages.sury.org/php/pool/main/p/php7.3/php7.3-imap_7.3.5-1+0~20190503093827.38+stretch~1.gbp60a41b_amd64.deb  404  Not Found
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

Tell me what am I doing wrong?
I have php 7.2, so I tried it like this - sudo apt install php7.2-imap, about the same answer...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2019-07-10
@Zimaell

Try to do so.

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.2-imap
sudo service apache2 restart

ps
Enable access for unsafe applications to your account.
Change your code a bit.
$imap = imap_open('{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX', 'login', 'password');
$emails = imap_search($imap, 'ALL');
if($emails){
 echo count($emails);
}
imap_close($imap);

Z
ZaurK, 2017-10-04
@ZaurK

The problem was solved by itself, probably due to a drop in communication, an error occurred, I waited and installed the framework without any problems

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question