Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

POP email

Status
Not open for further replies.

PhoenixDown

Programmer
Jul 2, 2001
279
CA
How do I connect to a POP server with an account username/password and display messages?
 
If you are looking for installable scripts to read your email via a web page, there's SquirrelMail ( . It says it does IMAP and SMTP, but it might do POP3, too), Popper ( kmMail ( NewMail (


If you are looking to home-grow your own, check PHP's IMAP/SMTP/NNTP family of functions.
 
Thanks.

I want to write my own, but my server only allows POP3 accounts.
 
To write your own, you should look up a tutorial on POP3.
The basic commands are
USER username - tells the server who is loggin in
PASS password - sends the password
LIST - lists all the new messages
STAT - gives you the current status
RETR mailno - retrieves a mail
QUIT - quits the POP3 session
Then all you would have to do would be to open a socket to the server and issue these commands. //Daniel
 
Do you know where I can find information on this? I tried php.net and I couldn't find anything.
 
PHP's imap family of functions will (at least according to the online manual) handle this.
 
My host doesn't support the c-client library and they refuse to install it. What else can I do?
 
You could write your own functions/classes that connects to the server and issues the commands.
This would connect to the server and retrieve a list of messages.
<?php
function isok($string)
{
if (preg_match(&quot;/^+OK/&quot;, $string))
return 1;
else
return 0;
}
$stream = fsockopen(&quot;mail.domain.tld&quot;, 110, $error, $errorno);
if (!$stream)
{
echo &quot;Couldn't connect: $error ($errorno).&quot;;
}
else
{
$buffer = fread($stream, 1024);
if (!isok($buffer))
echo &quot;Error: $buffer&quot;;
fwrite($stream, &quot;USER username&quot;);
$buffer = fread($stream, 1024);
if (!isok($buffer))
echo &quot;Error: $buffer&quot;;
fwrite($stream, &quot;PASS password&quot;);
$buffer = fread($stream, 1024);
if (!isok($buffer))
echo &quot;Unable to login.&quot;;
else
{
fwrite($stream, &quot;LIST&quot;);
$buffer = fread($stream, 1024);
preg_match(&quot;/^+OK ([0-9]+) messages/i&quot;, $buffer, $matches);
echo &quot;You have &quot; . $matches[1] . &quot; new messages.&quot;;
}
fwrite($stream, &quot;QUIT&quot;);
fclose($stream);
} //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top