Home » Php » php – imap_open() works locally but not on server

php – imap_open() works locally but not on server

Posted by: admin February 25, 2020 Leave a comment

Questions:

The issue is i’m trying to get the last email from my email using php, and it works fine locally. But then I uploaded the script to the client’s server, and I don’t get a response. When I check the logs, I get this:

[12-Feb-2020 08:43:21 location] PHP Warning:  imap_open(): Couldn't open stream {<mail>:143/imap}INBOX in /path/triggerCall.php on line 2
[12-Feb-2020 08:43:21 location] PHP Warning:  imap_headers() expects parameter 1 to be resource, boolean given in /path/triggerCall.php on line 7
[12-Feb-2020 08:43:21 location] PHP Warning:  imap_num_msg() expects parameter 1 to be resource, boolean given in /path/triggerCall.php on line 14
[12-Feb-2020 08:43:21 location] PHP Warning:  imap_header() expects parameter 1 to be resource, boolean given in /path/triggerCall.php on line 16
[12-Feb-2020 08:43:21 location] PHP Warning:  imap_fetchbody() expects parameter 1 to be resource, boolean given in /path/triggerCall.php on line 20
[12-Feb-2020 08:43:21 location] PHP Warning:  imap_close() expects parameter 1 to be resource, boolean given in /path/triggerCall.php on line 40

This is the code:

$inbox = imap_open('{<mail>:143/imap}', '<username>', '<password>');

$headers = imap_headers($inbox);

$last = imap_num_msg($inbox);

$header = imap_header($inbox, $last); 

$body = imap_fetchbody($inbox, $last,1);

I have tried:

{<mail>:993/imap/novalidate-cert}INBOX
{<mail>:995/pop3/tls}INBOX
{<mail>:995/pop3/ssl}INBOX
{<mail>:993/imap/ssl}INBOX
{<mail>:110/pop3}INBOX
{<mail>:993/imap/tls/novalidate-cert}INBOX
{<mail>:143}INBOX

But none of those approaches work. Any ideas?

How to&Answers:

Try this

$inbox = imap_open(‘{mail.gmail.com/ssl/novalidate-cert}INBOX’, ’email’, ‘password’);