tags:

views:

747

answers:

4

Hi ALl

I need to read emails from gmail but i cant connect to gmail pop3 server. Can anyone help me here ?

Here the code:

$pop3 = new POP3;
$pop3->server = 'pop.gmail.com';
$pop3->user = 'username';
$pop3->passwd = 'password';
$pop3->debug = true;
$pop3->pop3_connect()

The result:

Warning: fsockopen() [function.fsockopen]: unable to connect to pop.gmail.com:110 (Connection timed out) in /public_html/cron/pop3.php on line 64

Thanks

+1  A: 

According to this page (connecting to Gmail using Outlook Express), you have to use port 995 for POP3 access to Gmail, and furthermore, SSL must be enabled.

Wikipedia also states this:

E-mail clients can encrypt POP3 traffic using Transport Layer Security (TLS) or Secure Sockets Layer (SSL). A TLS/SSL connection is negotiated using the STLS command. Some clients and servers, like Google Gmail, instead use the deprecated alternate-port method, which uses TCP port 995 (POP3S).

Peter
A: 

I'm not sure if it will help you, but GMAIL has an ATOM feed. I wrote a PHP script to download the Atom Feed, using CURL, so that I could check my email on my antiquated cell phone that only supported very simple HTML. So, depending on what you want to do, it might be easier to download and process the ATOM feed than it is to connect to the POP server.

Kibbee
A: 

I don't know what class you're using -- but for instance, using Daniel Lemos' package is shown below. The key is choosing the right port (995), and the right encryption method (TLS set to true for whatever pop3 package you are using). For example, you could use something like the below to initiate the connection. Not a big fan of how this class is architected, or the sample code (lot of nested if statements), but it does the job.

$pop3=new pop3_class();
$apop=0;
$pop3->authentication_mechanism="USER";
$pop3->debug=0;
$pop3->html_debug=1;
$pop3->join_continuation_header_lines=1;
$pop3->hostname = "pop.gmail.com";
$pop3->port = 995; // The port that gmail uses...
$pop3->tls = 1; // This is encryption
$user = "someuser";
$password = "some password";

if( !empty($error=$pop3->Open()) ){
    die( "Something terrible happened..." );
}

$pop3->Login($user,$password,$apop);
Josh
A: 

I think there are two easy options to your email:

  • Cron atom feed like Kibbee says. But then you will have a little delay between when message was sent and when you fetch it.

  • Use http://smtp2web.com/ which will post your email to your website which means a lot shorter delay. Offcourse privacy should not be crucial, because your mail will pass through intermediate.

Alfred