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.
