您的位置:首页网页设计PHP实例 → 构建简单的Webmail系统

构建简单的Webmail系统

时间:2004/11/7 3:24:00来源:本站整理作者:蓝点我要评论(0)

这是一段Web Mail的示范代码,功能不是很强,但是结构还比较完整,主要的功能如查看文件夹,查看信件,回复,写信都有。但是程序中没有考虑附件解读和发送的问题。 (原文在 这里)。仅推荐给希望了解Webmail编程的网友做个参考。更加完善的Webmail请大家到 这里查找。

请注意:程序中使用了http认证功能,此功能需配合apache服务器使用。









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

将以下代码分别存为 index.php3, imapfuncs.phl

配置imapfuncs.phl文件中的$M_HOST = "localhost"; $M_MAILSERVER = "transit.fast.no";

然后浏览 index.php3 即可.  

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

index.php3




/* $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);



?>





<?PHP echo "$M_SYSNAME"; ?>















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);

}

?>






























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

imapfuncs.phl






/* $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 "
\n";

echo "
\n";



echo "";

echo "";

echo "\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 "\n";

echo " \n";

echo " ";

echo "";

echo "\n";

echo "\n";

}



if ($num <= 0) {

echo "\n";

}



echo "\n";



echo "
FromSubjectDate
$from$subj$date

";

echo "No messages in mailbox";

echo "

";

echo "";

echo "";

echo "";

echo "
\n";

echo "
\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 "
\n";

echo "\n";

echo "\n";

echo "\n";

echo "\n";

echo "
Message #$msgno: $from / $subj
\n"; 

echo "From: $from\n";

echo "Subject: $subj\n";

echo "Date: $date\n";

echo "
\n";

echo "$body\n";

echo "
";



echo "
";

echo "\n";

echo "\n";

echo "\n";

echo "";

echo "";

echo "     ";



echo "
\n";

echo "
\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 "
\n";

echo "\n";

echo "\n";

echo "";

echo "\n";



echo "";

echo "\n";



echo "
To:
Subject:
";

echo ""; 

相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 我的php文件怎么打开_php运算符怎么写 php 如何生成静态页面的函数PHP生成图片缩略图PHP session常见问题集锦及解决办法PHP实现同步远程Mysql

人气排行 DEDE在文章列表文章没有缩略图的不显示图片php+mysq修改用户密码我的php文件怎么打开_如何打开php文件的办法FCKeditor的配置和使用方法使用dedecms建站教程PHP+Ajax实现分页技术图片存储与浏览一例Linux+Apache+PHP+MySQLPHP生成图片缩略图