Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Mini-mail / Private Messaging system Jump to:  
Category: >> PHP Code >> Mini-mail / Private Messaging system Bookmark and Share

<< lastnext >>

Snippet Name: Mini-mail / Private Messaging system

Description: Internal Mail System or private messaging system.
Easy to embed into your own projects.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 01st, 2009

mail.php: 
 
<?PHP 
 
INCLUDE("dbconn.php"); 
$result1=MYSQL_QUERY("select * from users WHERE username='$username'") or DIE ("cant do it"); 
$row100 = MYSQL_FETCH_ARRAY($result1); 
?> 
| <a href="mail.php?action=compose">Compose</a> | <a href="mail.php?action=inbox">Inbox</a> | 
<table cellpadding="1" cellspacing="1" height="300" width="450"> 
<tr><td align=center valign=top> 
<?PHP 
IF($action==compose) { 
ECHO "<form action=mail.php?action=compose2 method=post>"; 
ECHO "<table>"; 
ECHO "<tr><td>Subject:</td><td><input type=text name=subject size=20 value=$subject></td></tr>"; 
ECHO "<tr><td>To:</td><td><input type=text name=to size=20 value=$to></td></tr>"; 
ECHO "<tr><td>Message:</td><td><textarea rows=16 cols=45 name=message></text></td></tr>"; 
ECHO "<tr><td><button type=submit>Send Mail!</button></td></tr>"; 
ECHO "</table>"; 
ECHO "</form>"; 
} 
IF($action==compose2) { 
$subject or DIE("Subject Blank"); 
$message or DIE("Message Black"); 
$to or DIE("To blank"); 
$date = DATE(YmdHis); 
 
 
$create = "INSERT INTO mail (UserTo, UserFrom, Subject, Message, SentDate, status) 
VALUES ('$to','$username','$subject','$message','$date','unread')"; 
$create2 = MYSQL_QUERY($create) or DIE("A letter could not be sent to $to!"); 
ECHO("Message Sent to $to!"); 
 
} 
IF($action==inbox) { 
$result=MYSQL_QUERY("select * from mail where UserTo='$username' ORDER BY SentDate DESC") or DIE ("cant do it"); 
ECHO "<table cellpadding=2 cellspacing=1 width=500 valign=top>"; 
WHILE ($row=MYSQL_FETCH_ARRAY($result)) { 
ECHO "<tr><td width=30>Mail:</td><td><a href=mail.php?action=veiw&mail_id=$row[mail_id]>$row[Subject]</a></td><td width=50> <a href=mail.php?action=delete&id=$row[mail_id]><center>Delete</a><br></td></tr>"; 
} 
ECHO "</table>"; 
} 
IF($action==veiw) { 
$result=MYSQL_QUERY("select * from mail where UserTo='$username' and mail_id=$mail_id") or DIE ("cant do it"); 
$row=MYSQL_FETCH_ARRAY($result); 
IF($row[UserTo]==$username) { 
} ELSE { 
ECHO "<font face=verdana><b>This isn't your mail!"; 
EXIT; 
} 
$query="UPDATE mail SET status='read' WHERE UserTo='$username' AND mail_id='$row[mail_id]'"; 
$query or DIE("An error occurred resulting that this message has not been marked read."); 
ECHO "<table border = 1 bordercolor = black width = 50% align=center><tr><td>$row[Subject]</td><td>$row[UserFrom]</td></tr><tr><td colspan='2'>$row[Message]<br><a href=mail.php?action=compose&to=$row[UserFrom]&subject=RE:$row[Subject]>Reply</a></td></tr></table>"; 
$rs = MYSQL_QUERY("UPDATE mail SET status='read' WHERE mail_id='$mail_id'"); 
} 
IF($action==delete) { 
$query = MYSQL_QUERY("DELETE FROM mail WHERE mail_id='$id' LIMIT 1"); 
IF($query) { 
ECHO "<font face=verdana>Message Deleted.</font>"; 
} ELSE { 
ECHO "The message wasnt deleted."; 
} 
} 
?> 
 
dbconn.php: 
<?PHP 
 
    $vusername = "username";              //your username for you local system 
    $pwd ="password";                  //password to accecss mySQL 
    $host = "localhost";               //host is localhost - even for most web hosts 
    $dbname = "database";               //db name to be accessed 
 
 
 
    //connect to db 
    //$conn=mysql_connect($host, $username, $pwd) or die ("Unable to connect to database"); 
 
    IF (!($conn=MYSQL_CONNECT($host, $vusername, $pwd)))  { 
        PRINTF("We couldn't connect to the database right now!"); 
        EXIT; 
    } 
       $db=MYSQL_SELECT_DB($dbname,$conn) or DIE("Unable to connect to database!"); 
 
?> 
 
 
tables: 
CREATE TABLE mail ( 
  UserTo tinytext NOT NULL, 
  UserFrom tinytext NOT NULL, 
  Subject mediumtext NOT NULL, 
  Message longtext NOT NULL, 
  status text NOT NULL, 
  SentDate text NOT NULL, 
  mail_id int(80) NOT NULL auto_increment, 
  PRIMARY KEY  (mail_id) 
) TYPE=MyISAM; 
 
Its easy to embed into your already made member site!
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 75 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?