I have written some code to fetch emails from a Gmail mailbox using Zend_Storage_Mail_Imap library. Till now, it was running fine on the development server (where imap_open was disabled). After I moved it to production(imap_open is enabled), the script has stoppped to work. Do I need to disable imap_open for it to work ?
UPDATE: Apparently, the issue is that of fsockopen(). The actual error message is:
Zend_Mail_Protocol_Exception with message 'cannot connect to host; error = Connection Timed Out (errno = 110)'
The relevant values in PHP.ini are:
allow_url_fopen = on
default_socket_timeout = 600 (on production) and 60 (on development)
I did find out, that inside the /library/Zend/Mail/Protocol/Imap.php, the timeout is mentioned as "const TIMEOUT_CONNECTION = 30".
Related
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.
I'm working on a small password reset script for our users, using PHP5 on an IIS7.5 server. I have LDAP over SSL enabled on our Active Directory controllers, and tested that it is working properly using ldp.exe
Here's the code to connect to the server:
$ldap_server = "ldaps://AD02.district.local";
$ldap_port = "636";
$ldap_user = "service_lookup#district.local";
$ldap_pass = "(goes here)";
$ds = ldap_connect($ldap_server,$ldap_port);
ldap_bind($ds,$ldap_user,$ldap_pass);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
However, when I execute the script, I get the following error:
Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server:
Can't contact LDAP server in D:\Sites\Lookup\search.php on line 11
If I set $ldap_server to use ldap:// instead of ldaps://, it'll connect (even with the port set to 636), but the actual reset function does not work ("server is unwilling to perform").
Is there a way to troubleshoot this further? Or does anyone know what may be wrong?dd
I know this is an old question. But today I encountered the same problem.
I had to apply the following solution to make it work:
Create a folder: C:\OpenLDAP\sysconf
Create a file 'ldap.conf' in C:\OpenLDAP\sysconf.
Make the content of the file: 'TLS_REQCERT never' (no quotes).
Save.
It should work now. According to the manual, “TLS_REQCERT never” prevents the server from requesting and/or checking any server certificate.
I have php page where I open and close IMAP connection to gmail (for testing purposes):
error_reporting(E_ALL);
$hostname = '{pop.gmail.com:995/imap/ssl/novalidate-cert}INBOX';
$mbox = imap_open($hostname, 'username', 'password') or die('Could not connect to the server!');
echo 'opened';
imap_close($mbox);
echo 'closed';
When I call this page, browser displays message that no response is received from the server. IMAP is enabled in php and function_exists('imap_open') returns true. I opened apache error log and each time I make a call to this page, message is added to log:
[notice] child pid XXXX exit signal File size limit exceeded (25)
I have looked all over the internet and found that this message is related to size of a log file being over 2GB. I checked all logs and none exceeds 500MB. I get the same result if I change hostname, username or password to any string. I don't know why I don't get any other message from php. How should I check what's going on and how to find out what's the error? Please ask if you need any other info.
My server runs on Slackware 11 and php version is 5.2.4 with IMAP and SSL (openssl) enabled.
If you've root access and this is a cPanel based server, you can simply run this command
/scripts/biglogcheck -v
This will list the log files that are 2GB. You should reset those file and it should solve this problem.
We use a PHP library that opens a connection to SMTP server to validate certain emails when registering new clients.
After a server change the script has started reporting constant connection timeouts:
fsockopen(): unable to connect to alt1.gmail-smtp-in.l.google.com:25
(Connection timed out) in /home/xxxxxx.php on line 195, referer: xxxxx
We can telnet the server via console as root, but not as apache user so we discarded it to be an iptables firewall issue (we use CSF).
Strange enough, it seems we can fsckopen other pòrts.
We are digging other issues of CSF configuration but so far we are completely lost as no other logs (lfd, iptables, syslog) reports anything.
SOLVED!
If CSF option SMTP_BLOCK is activated (=1) apache user ("www-data" in our case), needs to be added to the SMTP_ALLOWUSER directive for PHP (through Apache) to work with SMTP as a destination.
CSF firewall will block any outgoing connections to SMTP for users not allowed but without any logging to lfd.log
So I have a little problem with a PHP script I'm currently writing. To start off, let me say the script is supposed to connect to an IMAP mailbox, search for some emails and download their attachments. All of this is already coded and is working with my own gmail account. The problem arise when I try and connect to an exchange server. Short code excerpt :
$mbox = imap_open($host, $login, $password);
echo '<br/>' . imap_last_error() . '<br/>';
$emails = imap_search($mbox, 'FROM "patate#patate.com"', SE_UID);
I have tried two main $host "version" (with and without SSL) :
1 - {server:993/imap/ssl/novalidate-cert}INBOX
2 - {server:143/imap/novalidate-cert}INBOX
The novalidate-cert deal with a certificate error. I also tried the "notsl" parameters, for both of these, without any noticeable outcome. The error I get is this lovely message, absolutely not cryptic in any way, shape or form :
[CLOSED] IMAP connection broken (server response)
Additionally, I also receive these notices :
Notice: Unknown: Unknown GSSAPI failure: An invalid name was supplied (errflg=1) in Unknown on line 0
Notice: Unknown: GSSAPI mechanism status: Hostname cannot be canonicalized (errflg=1) in Unknown on line 0
Notice: Unknown: Retrying PLAIN authentication after AUTHENTICATE failed. (errflg=1) in Unknown on line 0
Notice: Unknown: Retrying PLAIN authentication after AUTHENTICATE failed. (errflg=1) in Unknown on line 0
Notice: Unknown: Can not authenticate to IMAP server: AUTHENTICATE failed. (errflg=2) in Unknown on line 0
Notice: Unknown: [CLOSED] IMAP connection broken (server response) (errflg=1) in Unknown on line 0
The first two especially puzzle me... I did try this script on another server, to make sure the issue was not related to my local network. After a lot of googling around, I only got this : http://www.phpfreaks.com/forums/index.php?topic=190628.0 which seems like a somewhat cumbersome fix.
Any ideas?
I'm having this same issue, it looks like the errors are being generated because an Exchange server advertises authentication protocols that it does not support (http://vision.eng.shu.ac.uk/mmvlwiki/index.php/Exchange). It also seems like this issue is isolated to linux servers as I have no issues with the exact same code on a Windows box. This has been a longstanding issue and PHP was recently patched (v 5.3.2) to allow you to disable certain authentication protocols (http://php.net/manual/en/function.imap-open.php). The below code works intermittently for me:
$this->inbox = imap_open("{server:993/imap/ssl/novalidate-cert}$inbox",
$username, $password, NULL, 1,
array('DISABLE_AUTHENTICATOR' => 'PLAIN')) or
die(var_dump(imap_errors()));
This also works intermittently:
$this->inbox = imap_open("{server:993/imap/ssl/novalidate-cert}$inbox",
$username, $password, NULL, 1,
array('DISABLE_AUTHENTICATOR' => 'GSSAPI')) or
die(var_dump(imap_errors()));
SO I ghetto rigged this it does seem to work...although it has the potential for an endless loop/DOS attack on my company's exchange server but /care
Hopefully there is a better solution, but this should help:
$tryCnt = 0;
while(!is_resource($this->inbox)){
$this->inbox = imap_open("{server.com:993/imap/ssl/novalidate-cert}$inbox",
$username, $password, NULL, 1,
array('DISABLE_AUTHENTICATOR' => 'GSSAPI'));
$tryCnt ++;
if(!is_resource($this->inbox)){
$this->inbox = imap_open("{server.com:993/imap/ssl/novalidate-cert}$inbox",
$username, $password, NULL, 1,
array('DISABLE_AUTHENTICATOR' => 'PLAIN'));
$tryCnt ++;
}
if($tryCnt > 20){
echo "Cannot Connect To Exchange Server:<BR>";
die(var_dump(imap_errors()));
}
}
I have a PHP script that connects to an OWA email server and brings back the content of an email using the imap_open PHP function. Using that content, it then creates a page in a MindTouch instance.
All of this code works correctly, but the script was reporting the GSSAPI failure errors shown above. In my web results page, success was (correctly) reported, but the page also displayed the GSSAPI error messages.
What I discovered in my code was that I was turning on error_reporting(E_ALL). When I changed the reporting level, the error message went away.
I know that the error is still there, and I don't know why. But, since all of my code is working correctly, I just wanted the error message to go away, because it was confusing my users.
Changing the reporting level to a lower one took care of that.