Build a simple Webmail system. This is a demo code of WebMail. the function is not very powerful, but the structure is still relatively complete. The main functions include viewing folders, viewing letters, replying, and writing letters. However, this is not a demo code of Web Mail in the program. it is not very functional, but the structure is still complete. The main functions include viewing folders, viewing letters, replying to letters, and writing letters. However, the program does not consider the issue of attachment interpretation and sending. (The original article is here ). It is only recommended to users who want to know Webmail programming for reference. For more comprehensive Webmail, please visit here.
Note: http authentication is used in the program. this function must be used with the apache server.
--------------------------------------------------------------------------------
Save the following code as index. php3, imapfuncs. phl
Configure $ M_HOST = "localhost" in the imapfuncs. phl file; $ M_MAILSERVER = "transit. fast. no ";
Then browse index. php3.
--------------------------------------------------------------------------------
Index. php3
/* $ Id: index. php3, v 1.3 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 12:12:32 borud Exp $ */
/* Retriable 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"
Message # $ msgno: $ from/$ subj |
\ N ";Echo"
\n"; echo "From: $from\n"; echo "Subject: $subj\n"; echo "Date: $date\n"; echo "
\n"; echo "$body\n"; echo " |
\ N ";Echo"
";
Echo" "; Echo" \ N "; Echo" \ N "; Echo" \ N "; Echo" "; Echo" "; Echo" "; Echo" |
\ N ";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"
To: | ";Echo"
|
\ N ";Echo"
Subject: | ";Echo"
|
\ N ";Echo"
"; Echo"$ Body";The demo code of consumer Mail is not very powerful, but the structure is still relatively complete. its main functions include viewing folders, viewing emails, replying to emails, and writing letters. But there is no... |