Home  >  Article  >  Backend Development  >  Build a simple Webmail system_PHP tutorial

Build a simple Webmail system_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:03:191292browse

This is a sample code for Web Mail. The function is not very strong, but the structure is relatively complete. The main functions are such as viewing folders, viewing letters, replying, and writing letters. However, the program does not consider the issue of attachment interpretation and sending. (Original article here). It is only recommended as a reference for netizens who want to understand Webmail programming. For more complete Webmail, please go here to find it.
Please note: The http authentication function is used in the program, and this function needs to be used with the apache server.




---------------------------------- ---------------------------------------------
Change the following The codes are saved as index.php3, imapfuncs.phl
Configure $M_HOST = "localhost"; $M_MAILSERVER = "transit.fast.no";
and then browse index.php3 in the imapfuncs.phl file.
-------------------------------------------------- ----------------------------------
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);

?>









< ;P>
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 "< TH> FromSubjectDate";
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 " < ;INPUT TYPE=CHECKBOX NAME=marked[] VALUE=$i>n";
echo " $from";
echo "< ;A href="$PHP_SELF?m=$mailbox&n=$i&cmd=display">$subj";
echo "$daten" ;
echo "n";
}

if ($num <= 0) {
echo "
";
echo "No messages in mailbox"; ;BR>n";
}

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

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"; <br>echo "From: $fromn"; <br>echo "Subject: $subjn"; <br>echo "Date: $daten"; <br>echo "<HR SIZE=2 NOSHADE>n"; <br>echo "$bodyn"; <br>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 ""; 

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316341.htmlTechArticleThis is a sample code for Web Mail. The function is not very strong, but the structure is relatively complete. The main functions are as follows Check folders, check letters, reply, and write letters. But there is nothing in the program...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn