Jump to content

Recommended Posts

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;
?>

Link to comment
https://forums.phpfreaks.com/topic/116851-pop3-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/116851-pop3-help/#findComment-600877
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/116851-pop3-help/#findComment-601590
Share on other sites

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?

 

Link to comment
https://forums.phpfreaks.com/topic/116851-pop3-help/#findComment-601904
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.