极乐门资源网 Design By www.ioogu.com
这是一段Web Mail的示范代码,功能不是很强,但是结构还比较完整,主要的功能如查看文件夹,查看信件,回复,写信都有。但是程序中没有考虑附件解读和发送的问题。 (原文在 这里)。仅推荐给希望了解Webmail编程的网友做个参考。更加完善的Webmail请大家到 这里查找。
请注意:程序中使用了http认证功能,此功能需配合apache服务器使用。




--------------------------------------------------------------------------------
将以下代码分别存为 index.php3, imapfuncs.phl
配置imapfuncs.phl文件中的$M_HOST = "localhost"; $M_MAILSERVER = "transit.fast.no";
然后浏览 index.php3 即可.  
--------------------------------------------------------------------------------
index.php3

<?PHP
/* $Id: index.php3,v 1.3 1999/04/14 12:12:32 borud Exp $ */

/* load the IMAP library functions we\'ve written */
include("imapfuncs.phl");

m_login($m);

?>
<HTML>
<HEAD>
<TITLE><?PHP echo "$M_SYSNAME"; ?></TITLE>
</HEAD>
<BODY bgcolor=#AAAAAA text=#000000 link=#440000 vlink=#440000 alink=#FF00FF>
<H1 ALIGN=CENTER><?PHP echo "$M_SYSNAME"; ?></H1>
<HR SIZE=1 NOSHADE>

<P>
<?PHP
if ($cmd == "delete") {
m_delete($marked, $m);
m_list($m);
}

elseif ($cmd == "display") {
m_display($n, $m);
}

elseif ($cmd == "compose" || $cmd == "reply") {
m_compose($n, $m);
}

elseif ($cmd == "send") {
m_send($to, $subject, $body);
m_list($m);
}

else {
m_list($m);
}
?>

<P>

<HR SIZE=1 NOSHADE>
<?PHP echo "User: $PHP_AUTH_USER"; ?>

</BODY>
</HTML>






--------------------------------------------------------------------------------
imapfuncs.phl

<?PHP /* -*-C++-*- */

/* $Id: imapfuncs.phl,v 1.4 1999/04/14 12:12:32 borud Exp $ */

/* configurable parameters */


$M_HOST = "localhost";
$M_MAILSERVER = "transit.fast.no\";

$M_COLOR_ODD = "#CCCCCC";
$M_COLOR_EVEN = "#EEEEEE";
$M_COLOR_HEAD = "#AAAAFF";
$M_COLOR_BG = "#FFFFFF";


/* globals */
$M_PORT = 143;
$M_SERVICE = "imap";
$M_SYSNAME = "Simple PHP3 IMAP Interface 1.0";
$M_MBOX = "{$M_HOST:$M_PORT/$M_SERVICE}";
$M_REALM = "IMAP Interface";
$MBOX = false;

/* functions */

function m_login ($mailbox = '')
{
global $MBOX, $M_REALM;
global $PHP_AUTH_USER, $PHP_AUTH_PW;

if ($MBOX) {
return true;
}

if (! $PHP_AUTH_USER) {
m_reject($M_REALM);
}

$MBOX = @imap_open(m_mailbox_name($mailbox), $PHP_AUTH_USER, $PHP_AUTH_PW);

if (! $MBOX) {
m_reject($M_REALM);
}

return true;
}


function m_list($mailbox = '')
{
global $MBOX, $PHP_SELF;
global $M_COLOR_ODD, $M_COLOR_EVEN, $M_COLOR_HEAD, $M_COLOR_BG;

/* if not logged into server, do so */
if (! $MBOX) {
if (! m_login($mailbox)) {
return false;
}
}

$num = imap_num_msg($MBOX);

echo "<FORM ACTION=$PHP_SELF TYPE=POST>\n";
echo "<CENTER><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=1 WIDTH=90%>\n";

echo "<TR ALIGN=LEFT BGCOLOR=$M_COLOR_HEAD>";
echo "<TH> </TH><TH>From</TH><TH>Subject</TH><TH>Date</TH>";
echo "</TR>\n";

for ($i=1; $i < ($num+1); $i++) {
$head = imap_header($MBOX, $i, 50, 50, 0);

$from = $head->fetchfrom;
$subj = $head->fetchsubject;
$date = m_date_format($head->date);

$bgcolor = ($i%2 == 0)?$M_COLOR_ODD:$M_COLOR_EVEN;

echo "<TR BGCOLOR=\"$bgcolor\">\n";
echo " <TD><INPUT TYPE=CHECKBOX NAME=marked[] VALUE=$i></TD>\n";
echo " <TD>$from</TD>";
echo "<TD><A href=\"$PHP_SELF?m=$mailbox&n=$i&cmd=display\">$subj</A></TD>";
echo "<TD>$date</TD>\n";
echo "</TR>\n";
}

if ($num <= 0) {
echo "<TR><TD ALIGN=CENTER COLSPAN=4 BGCOLOR=$M_COLOR_BG><BR>";
echo "<FONT SIZE=+1 COLOR=#FF0000>No messages in mailbox</FONT>";
echo "<BR><BR></TD></TR>\n";
}

echo "<TR BGCOLOR=$M_COLOR_HEAD><TD COLSPAN=4>";
echo "<INPUT TYPE=submit NAME=cmd VALUE=delete>";
echo "<INPUT TYPE=submit NAME=cmd VALUE=compose>";
echo "<INPUT TYPE=submit NAME=cmd VALUE=refresh>";
echo "</TD></TR>\n";

echo "</TABLE></CENTER>\n";
echo "</FORM>\n";

return true;
}


function m_display($msgno, $mailbox = '')
{
global $MBOX, $M_COLOR_HEAD, $M_COLOR_BG;
global $PHP_SELF;

if (! $MBOX) {
if (! m_login($mailbox)) {
return false;
}
}

$struc = imap_fetchstructure($MBOX, $msgno);
if (! $struc) {
return false;
}

$head = imap_header($MBOX, $msgno, 50, 50, 0);

$from = $head->fromaddress;
$subj = $head->subject;
$date = $head->date;
$body = htmlentities(imap_body($MBOX, $msgno));

echo "<CENTER>\n";
echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=10 WIDTH=100%>\n";
echo "<TR BGCOLOR=$M_COLOR_HEAD><TH>Message #$msgno: $from / $subj</TH></TR>\n";
echo "<TR BGCOLOR=$M_COLOR_BG><TD><PRE>\n";
echo "From: $from\n";
echo "Subject: $subj\n";
echo "Date: $date\n";
echo "<HR SIZE=2 NOSHADE>\n";
echo "$body\n";
echo "</PRE></TD></TR>\n";
echo "<TR BGCOLOR=$M_COLOR_HEAD><TD>";

echo "<FORM ACTION=$PHP_SELF METHOD=POST>";
echo "<INPUT TYPE=HIDDEN NAME=m VALUE=$mailbox>\n";
echo "<INPUT TYPE=HIDDEN NAME=n VALUE=$msgno>\n";
echo "<INPUT TYPE=HIDDEN NAME=marked[] VALUE=$msgno>\n";
echo "<INPUT TYPE=SUBMIT NAME=cmd VALUE=back>";
echo "<INPUT TYPE=SUBMIT NAME=cmd VALUE=reply>";
echo "     <INPUT TYPE=SUBMIT NAME=cmd VALUE=delete>";

echo "</TD></TR>\n";
echo "</TABLE>\n";
echo "</CENTER>\n";

return true;
}

function m_delete ($msgno, $mailbox='')
{
global $MBOX;

if (is_array($msgno)) {
while (list($dummy, $num) = each($msgno)) {
imap_delete($MBOX, $num);
}
imap_expunge($MBOX);
} else {
return false;
}

return true;
}

function m_compose ($msgno='', $mailbox='')
{
global $MBOX, $M_COLOR_HEAD, $M_COLOR_BG;
global $PHP_SELF, $PHP_AUTH_USER, $M_MAILSERVER;

if ($msgno != '') {
$head = imap_header($MBOX, $msgno, 150, 150, 0);
$to = $head->fromaddress;
$subject = "Re: " . $head->subject;
$body = "$to wrote:\n";
$body .= ereg_replace("\n","\n>", "\n" . imap_body($MBOX, $msgno));
} else {
$to = "";
$subject = "";
$body = "";
}

echo "<CENTER>\n";
echo "<FORM METHOD=POST ACTION=\"$PHP_SELF\">\n";
echo "<TABLE BORDER=0 CELLPADDING=5 CELLSPACING=0>\n";
echo "<TR bgcolor=$M_COLOR_HEAD><TD ALIGN=RIGHT>To:</TD>";
echo "<TD><INPUT TYPE=TEXT NAME=to value=\"$to\" SIZE=50></TD></TR>\n";

echo "<TR bgcolor=$M_COLOR_HEAD><TD ALIGN=RIGHT>Subject:</TD>";
echo "<TD><INPUT TYPE=TEXT NAME=subject value=\"$subject\" SIZE=50></TD></TR>\n";

echo "<TR bgcolor=$M_COLOR_BG><TD COLSPAN=2>";
echo "<TEXTAREA COLS=76 ROWS=10 NAME=body WRAP=hard>$body</TEXTAREA>"; 
标签:
|构建|建简|简单|单的|的W|We|eb|bm|ma|ai|il|l系|系统|统|

极乐门资源网 Design By www.ioogu.com
极乐门资源网 免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
极乐门资源网 Design By www.ioogu.com

评论“构建简单的Webmail系统”

暂无构建简单的Webmail系统的评论...

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。