ryy705 Posted July 27, 2008 Share Posted July 27, 2008 Hello, I am experimenting with sockets and pop3. I am trying to to connect to gmail with the following code. But it prints an empty string as a response. Should it not print out 200 OK? Could someone help me by pointing out what I am doing wrong. Many thanks in advance. <?php $sock = fsockopen('tcp://' . 'pop.gmail.com', '995'); fwrite($sock, 'USER ' . 'username' . "\r\n"); $response = trim(fgets($sock, 512)); echo $response; ?> Quote Link to comment https://forums.phpfreaks.com/topic/116851-pop3-help/ Share on other sites More sharing options...
Nhoj Posted July 27, 2008 Share Posted July 27, 2008 I'm not 100% sure how it would be done as I'm not very familiar with sockets & pop3, however this site does offer a bit of tutorialization on the subject: http://www.mustap.com/phpzone_post_95_sending-email-in-php-the-hac Quote Link to comment https://forums.phpfreaks.com/topic/116851-pop3-help/#findComment-600875 Share on other sites More sharing options...
unkwntech Posted July 27, 2008 Share Posted July 27, 2008 This is ultimately less about the sockets and more about the POP3 protocol. You will be just sending data formatted for the POP protocol, and filtering the incoming data based on the POP protocol. Specificly in regards to you question I know that the php manual page for mail() there is a user submited function in the comments to send email via Gmail so that may shed some light on things, link: http://www.php.net/mail. Quote Link to comment https://forums.phpfreaks.com/topic/116851-pop3-help/#findComment-600877 Share on other sites More sharing options...
ryy705 Posted July 27, 2008 Author Share Posted July 27, 2008 Thanks for your replies. POP3 is used for reading mail (Which is what I am trying to do). SMTP is used for sending emails. I could not find a function for using POP3 in the comments. Could you kindly specify the name of whoever posted it? Quote Link to comment https://forums.phpfreaks.com/topic/116851-pop3-help/#findComment-601060 Share on other sites More sharing options...
ryy705 Posted July 28, 2008 Author Share Posted July 28, 2008 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/116851-pop3-help/#findComment-601579 Share on other sites More sharing options...
JonnoTheDev Posted July 28, 2008 Share Posted July 28, 2008 Set $server and $portNum to your values if(!$handle = @fsockopen($server, $portNum, $errorNo, $errorString, 30)) { print "connection error"; exit(); } $response = fgets($handle, 4096); if(stristr($response, "+OK") === FALSE) { print "connection error"; exit(); } This is a very simple piece of code to start a connection off. Have you actually tested the connection using TELNET first? Quote Link to comment https://forums.phpfreaks.com/topic/116851-pop3-help/#findComment-601590 Share on other sites More sharing options...
ryy705 Posted July 28, 2008 Author Share Posted July 28, 2008 When I do telnet pop.gmail.com 955, I get: Connected to gmail-pop.l.google.com.Escape character is '^]'. And I don't get my prompt back. If I type in USER username I get: Connection closed by foreign host. I really don't know what to expect because this is the first time I am doing this. Both my code and your code establishes a connection but they do not get a response from the server. (Your code prints the second err message). What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/116851-pop3-help/#findComment-601904 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.