分享
 
 
 

一个简单的Webmail系统

王朝other·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

一个简单的Webmail系统

来源:sadly

这是一段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>\n";

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

echo "<TR bgcolor=$M_COLOR_HEAD><TD COLSPAN=2>";

echo "<INPUT TYPE=HIDDEN NAME=m VALUE=$mailbox>";

echo "<INPUT TYPE=SUBMIT NAME=cmd VALUE=send>";

echo "<INPUT TYPE=SUBMIT NAME=cmd VALUE=cancel>";

echo "</TD></TR>";

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

echo "</CENTER>\n";

}

function m_send ($to, $subject, $body)

{

global $PHP_AUTH_USER, $M_MAILSERVER, $M_SYSNAME;

if ($PHP_AUTH_USER && $M_MAILSERVER && $to && $body) {

$headers = "From: $PHP_AUTH_USER@$M_MAILSERVER\n";

$headers .= "Reply-to: $PHP_AUTH_USER@$M_MAILSERVER\n";

$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";

$headers .= "Content-Transfer-Encoding: 8bit\n";

$headers .= "X-Mailer: $M_SYSNAME/" . phpversion() . "\n";

return mail($to, $subject, $body, $headers);

}

return false;

}

function m_date_format($datestr)

{

if (ereg("([[:digit:]]{1,2})[[:space:]]+([[:alpha:]]{3})[[:space:]]+([[:digit:]]{4})",

$datestr, $regs)) {

return $regs[0];

}

return $datestr;

}

function m_mailbox_name ($mbx)

{

global $M_MBOX;

/* no mailbox specified means we map it to the inbox */

if ($mbx == "") {

return $M_MBOX . "INBOX";

}

/* replace some special chars */

$mbx = ereg_replace("[^[:alnum:]]", "_", $mbx);

return $M_MBOX . $mbx;

}

function m_reject($dom)

{

Header("HTTP/1.0 401 Unauthorized");

Header("WWW-authenticate: basic realm=\"$dom\"");

echo "Access denied\n";

exit;

}

/* make sure there is NO trailing space here!!! */

?>

--------------------------------------------------------------------------------

编辑整理:中国PHP自由联盟

[关闭窗口] - 2000-03-28 -

Copyright ? 2000 Chinese PHP Power All rights reserved.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有