Question : IMAP using PHP

I have been running the following code different ways for several days and am not able to get it to connect to the server. It hits the imap_open() function then locks up with no indication as what the cause it.

1. I have installed Outlook to run in IMAP connected to GMAIL using port 993 and it works fine
2. I have installed Apache on my local machine, localhost, port 25 but I am not sure I have the mail services configured right for this application.
3. I have locally installed PHP5 but not sure it is running IMAP
4. I have turned off the firewalls
5. I have also installed a program called stunnel but it requires changes to the stunnel.conf that may need to be set differently for this type of application.

Do you have some configuration instructions that I can follow to make this work from my local hosting?


function GmailReader( $user, $pass )
{

echo 'Attempting Mail Server Connection via POP
';
$username = '[EDITED]';
$password = '[EDITED]';
$connection = imap_open("{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX", $username, $password)
or die("can't connect: " . imap_last_error());

if($connection==TRUE)
{
echo 'Mail file is open using IMAP
';
}
else
{
echo 'Mail file is NOT open';
}

}

?>

Answer : IMAP using PHP

Save the code to a file on your web server.

phpinfo();
?>

And run the script via your browser.

It will show you all the settings you've got.

Or at the command line, type ...

php -m

or

php --ri imap

The first will list all modules you've got and the second will list the settings/version/state for imap (if it is loaded).

If you get ...

Extension 'imap' not present.

then you've not got it loaded.

Random Solutions  
 
programming4us programming4us