Winwebmail building a simple webmail system

Source: Internet
Author: User
Tags http authentication imap
This is a piece of web mail model code, the function is not very strong, but the structure is relatively complete, the main functions such as viewing folders, view letters, replies, letters are. However, the program does not consider the attachment interpretation and transmission problems. (the original is here). Only recommended for those who want to understand the webmail programming users to do a reference. More Perfect Webmail Please come here to find.
Note: The HTTP authentication feature is used in the program, which needs to 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 1999/04/14 12:12:32 Borud EXP $ */
/* Load the IMAP library functions we\ ' ve written */
Include ("IMAPFUNCS.PHL");
M_login ($m);
?>


<title><? PHP echo "$M _sysname";?></title>





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 to 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




echo "

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

The above describes the Winwebmail to build a simple webmail system, including winwebmail aspects of the content, I hope that the PHP tutorial interested in a friend to help.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.