構建簡單的Webmail系統_PHP

來源:互聯網
上載者:User
關鍵字 系統 簡單 構建 echo MBOX msgno TYPE
WebMail

這是一段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";

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 "$body";
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.