We have a php script to handle bounce mails. Now I have to take care of switching from the PEAR NET/POP3 library to the native-ish php-imap library.
The mailserver listens on a remote server on port 110 without ssl (obviously POP3).
However I am unable to open a connection to that server using the php-imap library using the following code:
imap_open("{example.com:110/pop3/notls}INBOX", $username, $password);
This results in the following errors:
Warning: imap_open(): Couldn't open stream {example.com:110/pop3/notls}INBOX in C:\xampp\htdocs\bounce-processing\info.php on line 1
Notice: Unknown: POP3 connection broken in response (errflg=2) in Unknown on line 0
The following PEAR POP3 implementation still works:
require("Net/POP3.php");
$pop3 = new Net_POP3();
$pop3->connect('example.com', 110)
$pop3->login($username, $password);
What I already tried:
imap_open("{IP-ADDRESS:110/pop3/notls}INBOX", $username, $password);
imap_open("{IP-ADDRESS:110/pop3/notls/user=$username}INBOX", $username, $password);
NOTE: I also tested this on different setups (CentOS / Apache 2.2, Ubuntu 14.04 / nginx, PHP 5.4, PHP 5.5, PHP 5.6, no different outcome.
What can I do? Debugging did not really help me - and that the pear class works freaks me out.
Thanks in advance!
EDIT: php binary is compiled with imap / ssl and the php-imap extension is enabled in the php.ini. If you know another future-proof way to make php talk to a pop3 mailserver, let me know. We don't want to use frameworks such as phpmailer etc.
EDIT2: telnet login works with a success rate of 40%. I was able to successfully log in 4 out of 10 times with correct credentials.
Output of the CAPA command:
CAPA
+OK Here's what I can do:
STLS
TOP
USER
LOGIN-DELAY 10
PIPELINING
UIDL
IMPLEMENTATION Courier Mail Server
.
I don't know if thats important, but the mailserver is in fact hosted by a dedicated server housing and hosting company.
EDIT3: Trying to connect via
{IP_ADDRESS:110/pop3}
returns the following errors:
Warning: imap_open(): Couldn't open stream {IP_ADDRESS:110/pop3} in C:\xampp\htdocs\bounce-processing\index.php on line 12
Notice: Unknown: Certificate failure for IP_ADDRESS: Server name does not match certificate.
Appending the flag novalidate-cert leads to a timeout.
Related
I use the PHP function imap_open to connect to a localhost dovecot server. It works most of the time, but sometimes I have warning:
PHP Warning: imap_open(): Couldn't open stream
{imap.fluoo.com/imap:993/ssl/novalidate-cert}INBOX Can not
authenticate to IMAP server: [CLOSED] IMAP connection broken
(authenticate)
When this occur I have in mail log:
Sep 3 10:38:01 bipbip dovecot: imap(robot.info#XXXXXXX.com)<3325276><ovIENBPLAsV/AAAB>: Connection closed (No commands sent) in=0 out=394 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
I haven't this error for distant connexion with Thunderbird or Outlook, only for PHP in localhost.
I have read that the issue is due to SSL but I don't want to disable it.
I use PHP 7.4.22 and dovecot 2.3.7.2.
If you can help me because I want to try to avoid use # operator to delete warning...
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 = 'login#gmail.com';
// 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.
The issue doesn't seem to be PHP related, but connection related, especially if the script works on a different machine.
There are two things you need to check.
Can you outbound connect on port 993 (is it open for OUT connections). You can try telnet to check that and if it doesn't work verify your Linux Firewall settings.
Do you have SELinux enabled and if you do did you check your audit log for AVC denials? It you have issues you may need to enable your httpd_can_network_connect or even do an audit2allow as the port might be non-standard. Be careful what you are doing as you can disrupt security on your server.
I am having some issues with imap_open.
This is the error I am getting:
Message: imap_open(): Couldn't open stream
{imap-mail.outlook.com:993/imap/ssl/novalidate-cert}INBOX
No matter if its imap using ssl on port 993 or pop ssl on port 995, I am getting the same error.
Message:
Unknown: Can't open mailbox
{imap-mail.outlook.com:993/imap/ssl/novalidate-cert}INBOX: invalid
remote specification (errflg=2)
I have the following setup:
Mac OSX Yosemite
Mamp Pro running PHP 5.6.10
Here is what I've done to troubleshoot:
I have apple mail setup to check my gmail account using imap ssl on port 993. I will assume if apple mail can retrieve mail, the port is open.
I went to Security and Privacy and did a PORT SCAN... 993 and 995 were not open... strange.
I do not have Mac Firewall enabled.
When using non ssl, on port 110 pop, this appears to be working fine.
Can anyone assist to see what may be the cause.
Check phpinfo() to see if php is complied --with-imap-ssl
http://www.bartvanasselt.nl/mamp-pro-using-imap-with-ssl/
Also can try tunneling:
Workaround for PHP IMAP functions? Trying to work with incoming email on localhost using XAMPP
In the project I am working on right now, I am trying to add the functionality where I can change the status of a ticket from 'closed' to 'reopened' when the user sends an email to the support desk. I would also like to save their email reply to the database.
The problem I am running into is that I cannot get PHP's IMAP functions to work on my current Apache configuration. From looking at quite a few posts here at stackoverflow and other places, it seems that the problem is OpenSSL is not enabled in the standard configuration. So for example, when I run this code:
<h1>IMAP testing!</h1>
<?php
$connect = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
$user = "my email address #gmail.com";
$pass = "my password";
$mailbox = imap_open($connect, $user, $pass);
?>
I get the error:
Can't open mailbox {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX: invalid remote specification.
Is there anything I can do, short of recompiling PHP, to mimic IMAP functionality on my local machine to be able to continue developing the functionality of working with email (email piping)?
Some notes on my current configuration, just in case it helps:
OS X 10.7.4
PHP v.5.3.1
UPDATE -
I am almost there (thanks to dAm2K)!
I installed Stunnel (using Mac Ports), got everything configured finally and ran the command:
sudo stunnel /opt/local/etc/stunnel/stunnel.conf -c -d 127.0.0.1:443 -r imap.gmail.com:993
(For whatever reason I had to add the path to the .conf file)
Now my code looks like this:
<?php
$connect = "{localhost:443}INBOX";
$user = "my email address #gmail.com";
$pass = "my password";
$mailbox = imap_open($connect, $user, $pass);
?>
Now when I load the page, it just hangs for 30 seconds or so and gives the warning:
Notice: Unknown: Connection failed to localhost,443: Operation timed out (errflg=2) in Unknown on line 0
What is interesting is that if I change $connect to:
$connect = "{localhost:443/ssl}INBOX";
or
$connect = "{localhost:443/novalidate-cert}INBOX";
I get the original error, which was:
Notice: Unknown: Can't open mailbox {localhost:443/novalidate-cert}INBOX: invalid remote specification (errflg=2) in Unknown on line 0
Any ideas? Just a guess but could it maybe be something to do with the setup of stunnel, like having a self-signed cert or something with the stunnel.conf file I am missing?
Thanks a lot.
Tim
You probably have a firewall that blocks outgoing TCP packets going to imap.gmail.com on port 993.
Ask your sysadmin to check for outgoing TCP on dport 993 (imaps).
Also check if your DNS is resolving imap.gmail.com:
The command:
telnet imap.gmail.com 993
should give you a valid connection. If it doesn't succeed you found the problem.
You may want to install a IMAP server on your development machine so to continue the development offline... you can install "courier imap" package but it's not a very simple task...
If the connection succeded and the command:
openssl s_client -connect imap.gmail.com:993
give you a valid connection, the problem could be that your libc-client doesn't have SSL support compiled in. In this case you cannot use imaps with PHP, and you could use the "stunnel" command to forward clear traffic originating on your local machine going encrypted to gmail IMAP servers.
The command:
stunnel -c -d 127.0.0.1:443 -r imap.gmail.com:993
should do the trick. This way you can connect your PHP script to 127.0.0.1:443:
<?
$connect = "{localhost:443}INBOX";
?>
My project uses PHP JavaBridge, I have installed WAMP, JRE 6.0, and Tomcat 6.0.32
I can now access http://localhost:8080/ successfully but when I run my PHP site it gives me the following error
warning: fsockopen() [function.fsockopen]: unable to connect to localhost:8080 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. )
Can anyone please help me with this issue?
EDIT
Forgot to mention that I am using Windows 7
My comment above worked as a solution and hence this answer, so that in future others get it.
Can you 127.0.0.1:8080 instead of localhost:8080? See what do you get?
fsocketopen takes the hostname and it should be a valid domain, in your case, (in general) it could be a valid domain as long as you have an entry for localhost in your hosts file (C:\Windows\System 32\drivers\etc\hosts). See if you have something similar to that.