建立簡單的Webmail系統_PHP教程

WBOY
發布: 2016-07-21 16:03:19
原創
1323 人瀏覽過

這是一段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 = "#CCC_ODD; >$M_COLOR_EVEN = "#EEEEEE";
$M_COLOR_HEAD = "#AAAAFF";
$M_COLOR_BG = "#FFFFFF";


/ globals = 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 = '')
{
function m_login ($mailbox = '')
{
MBOX, $M_REALM;
global $PHP_AUTH_USER, $PHP_AUTH_PW;

if ($MBOX) {
return true;
}

m_reject($M_REALM);
}

$MBOX = @imap_open(m_mailbox_name($mailbox), $PHP_AUTH_USER, $PHP_AUTH_PW)
; {
m_reject($M_REALM);
}

return true;
}


function m_list($box = '')

function m_list($box = '''')
'' 🎜>global $MBOX, $PHP_SELF;
global $M_COLOR_ODD, $M_COLOR_EVEN, $M_COLOR_HEAD, $M_COLOR_BG;

/* if not logged inifof 🎜 if* if not logg. MBOX) {
if (! m_login($mailbox)) {
return false;
}
}

$num = imap_num_msg($MBOX);

$num = imap_num_msg($MBOX);

$num = imap_num_msg($MBOX);

$num = imap_num_msg($MBOX);

$num = imap_num_msg($MBOX);

$num = imap_num_msg($MBOX);

$num = imap_num_msg($MBOX);

$num = imap_num_msg($MBOX); >echo "
n";
echo "
n";

echo🎜>echo "";
echo "" ;
echo "n";

for ($i=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 echo " n"; }

echo "n";

echo "
From Subject Date
$from$subj$date

"; echo "No messages in mailbox"; echo "

";
echo "";
echo "";
echo "";
echo "
n";
echo "
n";

傳回true;
}


函數;
}


函數;
}


函數;
}


函數m_display($msgno, $mailbox = '')
{
全域$MBOX, $M_COLOR_HEAD, $M_COLOR_BG;
全域$PHP_SELF;

if (!! >if (!m_login($mailbox)) {
回傳false;
}
}

$struc = imap_fetchstruct($MBOX, $msgno);
if (!$ struc) {
回傳false;
}

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

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

回顯「
n」;
echo "n";
echo "n";
echo "n";
echo "n」;
echo "
訊息# $msgno: $from / $subj
n"; <br>echo“來自:$fromn” ; <br>echo "主題:$subjn"; <br>echo "日期:$daten"; <br>echo "<hr size="2" noshade>n"; <br>回顯「$bodyn」; <br>echo "
登入後複製
";

echo "
";
echo "n";
echo "n";
echo "n";
echo "";
echo "";
echo "     ";

回顯「
n";
回顯「
n」;

回傳true;
}

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

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


回傳false; }

函數m_compose ($msgno='', $mailbox='')
{
全域$MBOX, $M_COLOR_HEAD, $M_COLOR_BG; <_lf>全域$PHP PHP_AUTH_USER,$M_MAILSERVER;

if ($msgno != '') {
$head = imap_header($MBOX, $msgno, 150, 150, 0);
$to = $head ->fromaddress;
$subject =「回覆:」。 $head->主題;
$body = "$to 寫: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 "
至:
主題:
"; echo " "; 

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316341.htmlTechArticle這是一段Web Mail的示範程式碼,功能不是很強,但是結構還比較完整,主要的功能如查看資料夾,查看信件,回复,寫信都有。但程式中沒有...
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板