动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   PHP → 阅读文章

 线收邮件

作者来源: 
阅读 1242 人次 , 2006-4-18 15:41:00 

 

一个可以在线收邮件的东东

不能收MINE的信件。可以考虑使用BASE64解码什么东东来实现。具体我忘了。
刚刚写出来的。还不是很成熟。

//input.html
////////////////////////////////////////////////////
<html>
<head>
<title>pop mail form</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#FFFFFF">
<form method="post" action="check.php">
<table width="78%">
<tr>
<td width="49%" height="17">
请输入你的电子邮件账号信息:</td>
<td width="51%" height="17">&nbsp;</td>
</tr>
<tr>
<td width="49%">
<div align="right">
用户名:</div>
</td>
<td width="51%">
<input type="text" name="username">
</td>
</tr>
<tr>
<td width="49%">
<div align="right">
密码:</div>
</td>
<td width="51%">
<input type="password" name="passwd">
</td>
</tr>
<tr>
<td width="49%">
<div align="right">
主机名:</div>
</td>
<td width="51%">
<input type="text" name="pophost">
</td>
</tr>
<tr>
<td width="49%">
<div align="center">
<input type="submit" name="check" value="
确定">
</div>
</td>
<td width="51%">
<div align="center">
<input type="reset" name="Reset" value="
重来">
</div>
</td>
</tr>
</table>
</form>
</body>
</html>

//check.php
/////////////////////////////////////////
<?
include ("./mail.php");
if ($check){
$pop3 = pop3_open("$pophost", "110");
if (!$pop3) {
printf("[ERROR]
未能与主机正确连接!<BR>\n");
return 0;
}

if (!pop3_user($pop3, "$username")) {
printf("[ERROR]
错误的用户名?lt;BR>\n");
return 0;
}

if (!pop3_pass($pop3, "$passwd")) {
printf("[ERROR]
密码错误!<BR>\n");
return 0;
}

$articles = pop3_list($pop3);
if (!$articles) {
printf("[ERROR]
列表错误!<BR>\n");
return 0;
}
print "<table width=\"100%\" border=1>";
print "<tr><td>
状态</td><td>发信人</td><td>主题</td></tr>";
for ($i = 1; $i < $articles ["count"] + 1; $i++)
{
$data = pop3_retr($pop3,$i);
if (substr($data[9],8,2)=="RO") $read="
已读";
else $read="
未读";
print "<tr><td>$read</td><td>$data[5]</td><td><a
href=\"readmail.php?username=$username&passwd=$passwd&pophost=$pophost&no=$i\">$data[8]</a><

/td></tr>";
}
print "</table>";
}
?>
//mail.php
/////////////////////////////////////////
<?
function pop3_open($server, $port)
{
global $POP3_GLOBAL_STATUS;

$pop3 = fsockopen($server, $port);
if ($pop3 <= 0) return 0;

$line = fgets($pop3, 1024);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);

if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;

return $pop3;
}

function pop3_user($pop3, $user)
{
global $POP3_GLOBAL_STATUS;

fputs($pop3, "USER $user\r\n");
$line = fgets($pop3, 1024);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);
if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;
return 1;
}

function pop3_pass($pop3, $pass)
{
global $POP3_GLOBAL_STATUS;

fputs($pop3, "PASS $pass\r\n");
$line = fgets($pop3, 1024);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);
if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;
return 1;
}

function pop3_stat($pop3)
{
global $POP3_GLOBAL_STATUS;

fputs($pop3, "STAT\r\n");
$line = fgets($pop3, 1024);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);
if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;
if (!eregi("+OK (.*) (.*)", $line, $regs))
return 0;

return $regs[1];
}

function pop3_list($pop3)
{
global $POP3_GLOBAL_STATUS;

fputs($pop3, "LIST\r\n");
$line = fgets($pop3, 1024);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);
if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;
$i = 0;
while (substr($line = fgets($pop3, 1024), 0, 1) <> ".")
{
$articles[$i] = $line;
$i++;
}
$articles["count"] = $i;

return $articles;
}

function pop3_retr($pop3, $nr)
{
global $POP3_GLOBAL_STATUS;

fputs($pop3, "RETR $nr\r\n");
$line = fgets($pop3, 1024);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);
if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;
while (substr($line = fgets($pop3, 1024), 0, 1) <> ".")
{
$data[$i] = $line;
$i++;
}
$data["count"] = $i;

return $data;
}

function pop3_dele($pop3, $nr)
{
global $POP3_GLOBAL_STATUS;

fputs($pop3, "DELE $nr\r\n");
$line = fgets($pop3, 1024);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);
if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;
return 1;
}
function pop3_quit($pop3)
{
global $POP3_GLOBAL_STATUS;

fputs($pop3, "QUIT\r\n");
$line = fgets($pop3, 1024);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
$POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);

if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;

return 1;
}

function smtp_open($server, $port)
{
global $SMTP_GLOBAL_STATUS;

$smtp = fsockopen($server, $port);
if ($smtp < 0) return 0;

$line = fgets($smtp, 1024);

$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1);
$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024);

if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "2") return 0;

return $smtp;
}


function smtp_helo($smtp)
{
global $SMTP_GLOBAL_STATUS;

/* 'localhost' always works [Unk] */
fputs($smtp, "helo localhost\r\n");
$line = fgets($smtp, 1024);
$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1);
$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024);

if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "2") return 0;

return 1; }

function smtp_ehlo($smtp)
{
global $SMTP_GLOBAL_STATUS;

/* Well, let's use "helo" for now.. Until we need the
extra func's [Unk]
*/
fputs($smtp, "helo localhost\r\n");
$line = fgets($smtp, 1024);
$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1);
$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024);

if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "2") return 0;

return 1;
}


function smtp_mail_from($smtp, $from)
{
global $SMTP_GLOBAL_STATUS;

fputs($smtp, "MAIL FROM: <$from>\r\n");
$line = fgets($smtp, 1024);
$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1);
$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024);

if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "2") return 0;

return 1;
}

function smtp_rcpt_to($smtp, $to)
{
global $SMTP_GLOBAL_STATUS;

fputs($smtp, "RCPT TO: <$to>\r\n");
$line = fgets($smtp, 1024);
$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1);
$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024);

if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "2") return 0;


return 1;
}

function smtp_data($smtp, $subject, $data)
{
global $SMTP_GLOBAL_STATUS;

fputs($smtp, "DATA\r\n");
$line = fgets($smtp, 1024);
$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1);
$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024);

if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "3") return 0;

fputs($smtp, "Mime-Version: 1.0\r\n");
fputs($smtp, "Subject: $subject\r\n");
fputs($smtp, "$data\r\n\r\n");
fputs($smtp, ".\r\n");
$line = fgets($smtp, 1024);
if (substr($line, 0, 1) <> "2")
return 0;

return 1;
}

function smtp_quit($smtp)
{
global $SMTP_GLOBAL_STATUS;

fputs($smtp, "QUIT\r\n");
$line = fgets($smtp, 1024);
$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1);
$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024);

if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "2") return 0;

return 1;
}

function mail_parse($mail)
{
$newmail = explode("\n",$mail);
$count = 0;
$result =
$newmail[4]."\n".$newmail[6]."\n".$newmail[7]."\n".$newmail[8]."\n";
return $result;
}

?>

//readmail.php
////////////////////////<?
include ("./mail.php");
$pop3 = pop3_open("$pophost", "110");
if (!$pop3) {
printf("[ERROR]
未能与主机正确连接!<BR>\n");
return 0;
}

if (!pop3_user($pop3, "$username")) {
printf("[ERROR]
错误的用户名!<BR>\n");
return 0;
}

if (!pop3_pass($pop3, "$passwd")) {
printf("[ERROR]
密码错误!<BR>\n");
return 0;
}

$data = pop3_retr($pop3,$no);
if (substr($data[9],8,2)=="RO") $read="
已读";
else $read="
未读";
$countall = count($data);
print "<CENTER><H2>
信件内容</H2></CENTER><BR>";
print "<table width =\"100%\"border=1>";
print "<tr><td>
发信人</td><td>";
$mailfrom = substr($data[5],5,strlen($data[5])-5);
print "$mailfrom<BR>\n";
print "</td></tr>";
print "<tr><td>
收信人</td><td>";
$mailto= substr($data[7],3,strlen($data[7])-3);
print "$mailto<BR>\n";
print "</td></tr>";
print "<tr><td>
主题</td><td>";
$subject = substr($data[8],8,strlen($data[8])-8);
print "$subject<BR>\n";
print "</td></tr>";
print "<tr><td>
内容</td><td>";
for ($count=10;$count<$countall;$count++)
print "$data[$count]<BR>\n";
print "</td></tr>";
print "<table>";

pop3_quit($pop3);
?>

 

  
 本文Tags邮件  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:一个oracle+PHP的查询的例子
· 下一篇:使用php4加速网络传输
· 简单介绍下 PHP5 中引入的 MYSQLI
· 浅谈PHP语法(4)
· 使用php的编码功能-实例调用(3)
· 域名转向系统的实现
· 谈谈如何在PHP中加入自己的函数库(一)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077