Jump to content

Archived

This topic is now archived and is closed to further replies.

binit

[SOLVED] imap_open(): IMAP Connection Broken Problem

Recommended Posts

Hi,

 

I'm trying to write  a PHP mail parsing code for accessing and retrieving messages from an inbox using a series of IMAP based functions.I'm getting an error in a basic PHP code which I've written using just the imap_open() function and not any other functions as of now.When I try to connect using the code I get the following error

Array ( [0] => [CLOSED] IMAP connection broken (server response) )

 

This is the actual code which I'm using:

 

<?php

$server = "mail.ttu.edu";

$user = "";
$pass = "";

//fscokopen test

echo "<br> --> imap php test...<br>";

$i = @fsockopen($server, 993, $errno, $errstr, 30);
if ($i){
echo "<br> -->fsockopen test...<br>";
} 

else {
echo $errno;
echo $errstr;
}


$i = @imap_open("{mail.ttu.edu:993}INBOX", $user, $pass);

if ($i){
echo "<br> --> connection successful....<br>";
}
else {
echo "<br> --> connection to server failed...<br>";
print_r(imap_errors());
}
?>

 

The error message which I'm getting is displayed exactly after 60 seconds from running the code.I'm not sure if it is from the server side or from the settings in my php.ini file.

 

Also note that fsockopen() is working fine and also telnet to port 993 of the server is working too.

 

It is kind of urgent so any help will be greately appreciated.

 

If you need any more inputs then please let me know.

Share this post


Link to post
Share on other sites

There is one more thing:

 

a line in the php.ini file says this:

 

max_input_time = 60	; Maximum amount of time each script may spend parsing request data

 

Can this have something to do with the problem?

 

Share this post


Link to post
Share on other sites

When I'm trying to change the parameters I'm getting some other error as well

 

for example if i change the server address to mail.ttu.edu/exchange (this is where the exchange server is running)

 

then I get the following error in place of the earlier error:

 

Array ( [0] => Can't open mailbox {mail.ttu.edu/exchange:993/imap}INBOX: invalid remote specification )

 

I'm trying to toggle between the various possible combinations as suggested by the imap_open() manual at php.net but I'm getting either of these 2 errors in all the cases

Share this post


Link to post
Share on other sites

The problem was finally solved.

 

I thought it would be a good idea if I put the solution here since the problem seems to be very common and I found lots of instances of this problem on the net but none of them could provide a working solution (at least for my case)

 

However I did manage to find a solution which is as follows:

 

1. First of all I installed stunnel (Stunnel is a program that allows you to encrypt arbitrary TCP connections inside SSL) from http://www.stunnel.org/

 

2. Then in the stunnel.conf file I made the following changes:

 

[imapsClient]
accept = localhost:143
connect  = mail.ttu.edu:993
client = yes
sslVersion = TLSv1

 

Note that you'll already find these lines in the conf file:

 

[imaps]
accept  = 993
connect = 143

 

I preferred to comment out these lines and replaced them by the ones mentioned above.

 

Also note that the settings which I changed in the stunnel.conf file are specific to my IMAP server (mail.ttu.edu:993) so you should make your changes accordingly.

 

3. What stunnel is essentially doing here is mapping the insecure IMAP connection (on port 143) at localhost to my imap server (mail.ttu.edu) on port 993.

 

4. After making these changes, run stunnel and try:

telnet localhost 143

 

if everything is working fine then you should be getting and OK message.

In my case I got this message:

 

OK Microsoft Exchange Server 2003 IMAP4rev1 server version 6.5.7638.1 (enceladus.net.ttu.edu) ready.

 

5. After this I tried the imap_open() function like this:

 

$imap = @imap_open("{localhost:143}INBOX", $user, $pass);

 

and it worked fine.This created an imap resource named imap.Now you can use series of imap related functions using this resource (imap).

 

Note that earlier I was trying to connect directly to the server using imap_open() function but now since stunnel is doing the mapping for me from localhost:143 to mail.ttu.edu:993 (IMAP over SSL) so I gave localhost:143 as the argument in imap_open() function.

 

If you need any more information regarding this issue then you can send me a PM.

I would be happy to help you as I have spent way too much time on this problem.  ;)

Share this post


Link to post
Share on other sites

 

I have a problem with access to my IMAP mail server in the first instance is not handling this matter. lo unico q one is that I have the service imap enabled on the server with these data

 

server: myServer

Port: 143

others not have SSL

 

When I try to connect with imap_open (.......)

 

q tells me I can not fault the one Authentication failed, but if I use the same code because I works wonders with the server google.

 

I was reading and apparently my problem is I q q Habra port with the function fsockopen

$fp = fsockopen("miServidor", 143, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {

    echo "ok";
    fclose($fp);  

 

 

and it is here where I get a connection ok, but now is not how to use that connection for once has the open connection to use the functions imap

 

Now, it is necessary to always keep q q use this type of connection, or can ask me q ports to be well able to connect so directly, I ask this for I do not want to go q q ahcer called irrational and tb have some basis for able to discuss something

 

thank everyone for their help

 

Greetings

 

 

excuse my bad English

 

Share this post


Link to post
Share on other sites

Hi ,

 

I tried your solution but it didn't worked at all !

It shows Error :

                      can't connect: [CLOSED] IMAP connection broken (server response)

 

Please help

 

 

The problem was finally solved.

 

I thought it would be a good idea if I put the solution here since the problem seems to be very common and I found lots of instances of this problem on the net but none of them could provide a working solution (at least for my case)

 

However I did manage to find a solution which is as follows:

 

1. First of all I installed stunnel (Stunnel is a program that allows you to encrypt arbitrary TCP connections inside SSL) from http://www.stunnel.org/

 

2. Then in the stunnel.conf file I made the following changes:

 

[imapsClient]
accept = localhost:143
connect  = mail.ttu.edu:993
client = yes
sslVersion = TLSv1

 

Note that you'll already find these lines in the conf file:

 

[imaps]
accept  = 993
connect = 143

 

I preferred to comment out these lines and replaced them by the ones mentioned above.

 

Also note that the settings which I changed in the stunnel.conf file are specific to my IMAP server (mail.ttu.edu:993) so you should make your changes accordingly.

 

3. What stunnel is essentially doing here is mapping the insecure IMAP connection (on port 143) at localhost to my imap server (mail.ttu.edu) on port 993.

 

4. After making these changes, run stunnel and try:

telnet localhost 143

 

if everything is working fine then you should be getting and OK message.

In my case I got this message:

 

OK Microsoft Exchange Server 2003 IMAP4rev1 server version 6.5.7638.1 (enceladus.net.ttu.edu) ready.

 

5. After this I tried the imap_open() function like this:

 

$imap = @imap_open("{localhost:143}INBOX", $user, $pass);

 

and it worked fine.This created an imap resource named imap.Now you can use series of imap related functions using this resource (imap).

 

Note that earlier I was trying to connect directly to the server using imap_open() function but now since stunnel is doing the mapping for me from localhost:143 to mail.ttu.edu:993 (IMAP over SSL) so I gave localhost:143 as the argument in imap_open() function.

 

If you need any more information regarding this issue then you can send me a PM.

I would be happy to help you as I have spent way too much time on this problem.  ;)

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.