动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > PHP实例
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ PHP实例 ]的信息

本月文章推荐
.基于mysql的bbs设计(一).
.PHP的栏目导航程序.
.在线竞拍系统的PHP实现框架(二).
.玩转虚拟域名◎+ . .
.用PHP实现WEB动态网页静态.
.一个程序下载的管理程序(二).
.用PHP发电子邮件.
.PHP+MYSQL的文章管理系统(二)&nb.
.使用MaxMind 根据IP地址对访问者.
.PHP+DBM的同学录程序(1).
.PHP的面向对象编程:开发大型PHP.
.PHP制作图型计数器的例子.
.使用sockets:从新闻组中获取文章.
.计算2000年01月01日起到指定日的.
.转换中文日期的PHP程序.
.实时抓取YAHOO股票报价的代码.
.BBS(php & mysql)完整版(五).
.推荐文章系统(一).
.PHP+DBM的同学录程序(3).
.PHP4实际应用经验篇(9).

pop3邮件收取一例

发表日期:2000-12-5 |


test_pop3.php

<HTML>
<HEAD>
<TITLE>Test for Manuel Lemos's PHP POP3 class</TITLE>
</HEAD>
<BODY>
<?
require("pop3.php");

$user="user";
$password="passwd";
$apop=0;
$pop3_connection=new pop3_class;
$pop3_connection->hostname="mail.xiaocui.com";
if(($error=$pop3_connection->Open())=="")
{
   echo "<PRE>Connected to the POP3 server &quot;$pop3_connection->hostname&quot;.</PRE>\n";
   if(($error=$pop3_connection->Login($user,$password,$apop))=="")
   {
      echo "<PRE>User &quot;$user&quot; logged in.</PRE>\n";
      if(($error=$pop3_connection->Statistics(&$messages,&$size))=="")
      {
         echo "<PRE>There are <b>$messages</b> messages in the mail box with a total of <b>$size</b> bytes.</PRE>\n";
         $result=$pop3_connection->ListMessages("",0);
         if(GetType($result)=="array")
         {
            for(Reset($result),$message=0;$message<count($result);Next($result),$message++)
               echo "<PRE>Message ",Key($result)," - ",$result[Key($result)]," bytes.</PRE>\n";
             if($messages>0)
            {
                if(($error=$pop3_connection->RetrieveMessage(1,&$headers,&$body,-1))=="")
                {
                  echo "<PRE>Message 1:\n---Message headers starts below---</PRE>\n";
                  for($line=0;$line<count($headers);$line++)
                     echo "<PRE>",HtmlSpecialChars($headers[$line]),"</PRE>\n";
                  echo "<PRE>---Message headers ends above---\n---Message body starts below---</PRE>\n";
                  for($line=0;$line<count($body);$line++)
                     echo "<PRE>",HtmlSpecialChars($body[$line]),"</PRE>\n";
                  echo "<PRE>---Message body ends above---</PRE>\n";
                     
                  }
               }
             if($error==""&&($error=$pop3_connection->Close())=="")
                  echo "<PRE>Disconnected from the POP3 server &quot;$pop3_connection->hostname&quot;.</PRE>\n";
         }
        else
           $error=$result;
      }
   }
}
if($error!="")
   echo "<H2>Error: ",HtmlSpecialChars($error),"</H2>";
?>
</BODY>
</HTML>


pop3.php

<?

class pop3_class
{
        var $hostname="";
        var $port=110;

        var $connection=0;
        var $state="DISCONNECTED";
        var $greeting="";
        var $must_update=0;
        var $debug=0;

        Function OutputDebug($message)
        {
                echo $message,"<br>\n";
        }

        Function GetLine()
        {
                for($line="";;)
                {
                        if(feof($this->connection))
                                return(0);
                        $line.=fgets($this->connection,100);
                        $length=strlen($line);
                        if($length>=2 && substr($line,$length-2,2)=="\r\n")
                        {
                                $line=substr($line,0,$length-2);
                                if($this->debug)
                                        $this->OutputDebug("< $line");
                                return($line);
                        }
                }
        }

        Function PutLine($line)
        {
                if($this->debug)
                        $this->OutputDebug("> $line");
                return(fputs($this->connection,"$line\r\n"));
        }

        Function OpenConnection()
        {
                if($this->hostname=="")
                        return("2 it was not specified a valid hostname");
                switch(($this->connection=fsockopen($this->hostname,$this->port)))
                {
                        case -3:
                                return("-3 socket could not be created");
                        case -4:
                                return("-4 dns lookup on hostname \"$hostname\" failed");
                        case -5:
                                return("-5 connection refused or timed out");
                        case -6:
                                return("-6 fdopen() call failed");
                        case -7:
                                return("-7 setvbuf() call failed");
                        default:
                                return("");
                }
        }

        Function CloseConnection()
        {
                if($this->connection!=0)
                {
                        fclose($this->connection);
                        $this->connection=0;
                }
        }

        Function Open()
        {
                if($this->state!="DISCONNECTED")
                        return("1 a connection is already opened");
                if(($error=$this->OpenConnection())!="")
                        return($error);
                $this->greeting=$this->GetLine();
                if(GetType($this->greeting)!="string"
                || strtok($this->greeting," ")!="+OK")
                {
                        $this->CloseConnection();
                        return("3 POP3 server greeting was not found");
                }
                $this->greeting=strtok("\r\n");
                $this->must_update=0;
                $this->state="AUTHORIZATION";
                return("");
        }
        
        Function Close()
        {
                if($this->state=="DISCONNECTED")
                        return("no connection was opened");
                if($this->must_update)
                {
                        if($this->PutLine("QUIT")==0)
                                return("Could not send the QUIT command");
                        $response=$this->GetLine();
                        if(GetType($response)!="string")
                                return("Could not get quit command response");
                        if(strtok($response," ")!="+OK")
                                return("Could not quit the connection: ".strtok("\r\n"));
                }
                $this->CloseConnection();
                $this->state="DISCONNECTED";
                return("");
        }

        Function Login($user,$password,$apop)
        {
                if($this->state!="AUTHORIZATION")
                        return("connection is not in AUTHORIZATION state");
                if($apop)
                {
                        if($this->PutLine("APOP $user ".md5($this->greeting.$password))==0)
                                return("Could not send the APOP command");
                        $response=$this->GetLine();
                        if(GetType($response)!="string")
                                return("Could not get APOP login command response");
                        if(strtok($response," ")!="+OK")
                                return("APOP login failed: ".strtok("\r\n"));
                }
                else
                {
                        if($this->PutLine("USER $user")==0)
                                return("Could not send the USER command");
                        $response=$this->GetLine();
                        if(GetType($response)!="string")
                                return("Could not get user login entry response");
                        if(strtok($response," ")!="+OK")
                                return("User error: ".strtok("\r\n"));
                        if($this->PutLine("PASS $password")==0)
                                return("Could not send the PASS command");
                        $response=$this->GetLine();
                        if(GetType($response)!="string")
                                return("Could not get login password entry response");
                        if(strtok($response," ")!="+OK")
                                return("Password error: ".strtok("\r\n"));
                }
                $this->state="TRANSACTION";
                return("");
        }

        /* Statistics method - pass references to variables to hold the number of
     messages in the mail box and the size that they take in bytes.  */

        Function Statistics($messages,$size)
        {
                if($this->state!="TRANSACTION")
                        return("connection is not in TRANSACTION state");
                if($this->PutLine("STAT")==0)
                        return("Could not send the STAT command");
                $response=$this->GetLine();
                if(GetType($response)!="string")
                        return("Could not get the statistics command response");
                if(strtok($response," ")!="+OK")
                        return("Could not get the statistics: ".strtok("\r\n"));
                $messages=strtok(" ");
                $size=strtok(" ");
                return("");
        }

        Function ListMessages($message,$unique_id)
        {
                if($this->state!="TRANSACTION")
                        return("connection is not in TRANSACTION state");
                if($unique_id)
                        $list_command="UIDL";
                else
                        $list_command="LIST";
                if($this->PutLine("$list_command $message")==0)
                        return("Could not send the $list_command command");
                $response=$this->GetLine();
                if(GetType($response)!="string")
                        return("Could not get message list command response");
                if(strtok($response," ")!="+OK")
                        return("Could not get the message listing: ".strtok("\r\n"));
                if($message=="")
                {
                        for($messages=array();;)
                        {
                                $response=$this->GetLine();
                                if(GetType($response)!="string")
                                        return("Could not get message list response");
                                if($response==".")
                                        break;
                                $message=intval(strtok($response," "));
                                if($unique_id)
                                        $messages[$message]=strtok(" ");
                                else
                                        $messages[$message]=intval(strtok(" "));
                        }
                        return($messages);
                }
                else
                {
                        $message=intval(strtok(" "));
                        return(intval(strtok(" ")));
                }
        }

        Function RetrieveMessage($message,$headers,$body,$lines)
        {
                if($this->state!="TRANSACTION")
                        return("connection is not in TRANSACTION state");
                if($lines<0)
                {
                        $command="RETR";
                        $arguments="$message";
                }
                else
                {
                        $command="TOP";
                        $arguments="$message $lines";
                }
                if($this->PutLine("$command $arguments")==0)
                        return("Could not send the $command command");
                $response=$this->GetLine();
                if(GetType($response)!="string")
                        return("Could not get message retrieval command response");
                if(strtok($response," ")!="+OK")
                        return("Could not retrieve the message: ".strtok("\r\n"));
                for($headers=$body=array(),$line=0;;$line++)
                {
                        $response=$this->GetLine();
                        if(GetType($response)!="string")
                                return("Could not retrieve the message");
                        switch($response)
                        {
                                case ".":
                                        return("");
                                case "":
                                        break 2;
                                default:
                                        if(substr($response,0,1)==".")
                                                $response=substr($response,1,strlen($response)-1);
                                        break;
                        }
                        $headers[$line]=$response;
                }
                for($line=0;;$line++)
                {
                        $response=$this->GetLine();
                        if(GetType($response)!="string")
                                return("Could not retrieve the message");
                        switch($response)
                        {
                                case ".":
                                        return("");
                                default:
                                        if(substr($response,0,1)==".")
                                                $response=substr($response,1,strlen($response)-1);
                                        break;
                        }
                        $body[$line]=$response;
                }
                return("");
        }

};

?>

上一篇:smtp邮件发送一例 人气:10859
下一篇:用PHP发送有附件的电子邮件 人气:9694
浏览全部的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-11-19 老Y文章管理系统 v2.2 bulid 081
2008-11-19 仿webmasterhome 网站收录查询 v
2008-11-19 小计天空儿童教育网站 v1.0
2008-11-19 小计天空儿服装企业网站 v1.0
2008-11-19 FLV地址解析小偷
2008-11-19 开良马克思影视下载插件 v1.0
2008-11-18 bbclone v0.4.9c 多国语言版
2008-11-18 雪晖在线投票系统 (asp) Build 2
2008-11-18 Piwik ( PHP统计系统,可以和GOOG
2008-11-15 BitTorrent 6.1.2 Build 13185
2008-11-15 BitComet 1.06
2008-11-15 SpeedFan 4.36 Final
2008-11-15 Windows Installer CleanUp Util
2008-11-15 Safari 3.2
2008-11-15 RealPlayer 11.0.0.835 简体中文
2008-11-15 QQ for Mac Preview 3 Build 394
2008-11-15 Vista优化大师3.20
2008-11-15 酷点 CoolDock 0.6
  发表评论
姓 名: 验证码:
内 容:
站长工具:网站收录查询 | Google PR查询 | ALEXA排名查询 | CSS在线编辑器 | 广告代码 | js/vbs加密 | md5加密 | 进制转换 | UTF-8 转换工具 | Html转换js | Html转换asp | Html转换php | Html转换perl
实用工具:汉字翻译拼音 | 拼音字典 | 符号对照表 | 个税计算 | 实时汇率查询换算 | 经典小工具 | 汉字简繁转换 | 普通单位换算 | 公制单位换算 | 生辰老黄历 | 国内电话区号 | 国家代码与域名缩写 | 文字加密解密 | 健康查询 | 万年历 | 汉字横竖排版 | 手机号码查询 | 计算器 | ip搜索
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報
防水工事·改修工事 フットサル大会 探偵
SEO対策 中国語教室 ホームページ作成