phool4fool
203.***.***.***Internal Mail System
With this code you can easily add a internal mail system to your site the varibles are easy to change!PHP Example:
PHP code:
0mail.php:
1<?php
2include("dbconn.php");
3$result1=mysql_query("select * from users WHERE username='$username'") or die ("cant do it");
4$row100 = mysql_fetch_array($result1);
5?>
6| <a href="mail.php?action=compose">Compose</a> | <a href="mail.php?action=inbox">Inbox</a> |
7<table cellpadding="1" cellspacing="1" height="300" width="450">
8<tr><td align=center valign=top>
9<?php
10if($action==compose) {
11echo "<form action=mail.php?action=compose2 method=post>";
12echo "<table>";
13echo "<tr><td>Subject:</td><td><input type=text name=subject size=20 value=$subject></td></tr>";
14echo "<tr><td>To:</td><td><input type=text name=to size=20 value=$to></td></tr>";
15echo "<tr><td>Message:</td><td><textarea rows=16 cols=45 name=message></text></td></tr>";
16echo "<tr><td><button type=submit>Send Mail!</button></td></tr>";
17echo "</table>";
18echo "</form>";
19}
20if($action==compose2) {
21$subject or die("Subject Blank");
22$message or die("Message Black");
23$to or die("To blank");
24$date = date(YmdHis);
25
26
27$create = "INSERT INTO mail (UserTo, UserFrom, Subject, Message, SentDate, status)
28VALUES ('$to','$username','$subject','$message','$date','unread')";
29$create2 = mysql_query($create) or die("A letter could not be sent to $to!");
30echo("Message Sent to $to!");
31
32}
33if($action==inbox) {
34$result=mysql_query("select * from mail where UserTo='$username' ORDER BY SentDate DESC") or die ("cant do it");
35echo "<table cellpadding=2 cellspacing=1 width=500 valign=top>";
36while ($row=mysql_fetch_array($result)) {
37echo "<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>";
38}
39echo "</table>";
40}
41if($action==veiw) {
42$result=mysql_query("select * from mail where UserTo='$username' and mail_id=$mail_id") or die ("cant do it");
43$row=mysql_fetch_array($result);
44if($row[UserTo]==$username) {
45} else {
46echo "<font face=verdana><b>This isn't your mail!";
47exit;
48}
49$query="UPDATE mail SET status='read' WHERE UserTo='$username' AND mail_id='$row[mail_id]'";
50$query or die("An error occurred resulting that this message has not been marked read.");
51echo "<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>";
52$rs = mysql_query("UPDATE mail SET status='read' WHERE mail_id='$mail_id'");
53}
54if($action==delete) {
55$query = mysql_query("DELETE FROM mail WHERE mail_id='$id' LIMIT 1");
56if($query) {
57echo "<font face=verdana>Message Deleted.</font>";
58} else {
59echo "The message wasnt deleted.";
60}
61}
62?>
63
64dbconn.php:
65<?php
66
67 $vusername = "username"; //your username for you local system
68 $pwd ="password"; //password to accecss mySQL
69 $host = "localhost"; //host is localhost - even for most web hosts
70 $dbname = "database"; //db name to be accessed
71
72
73
74 //connect to db
75 //$conn=mysql_connect($host, $username, $pwd) or die ("Unable to connect to database");
76
77 if (!($conn=mysql_connect($host, $vusername, $pwd))) {
78 printf("We couldn't connect to the database right now!");
79 exit;
80 }
81 $db=mysql_select_db($dbname,$conn) or die("Unable to connect to database!");
82
83?>
84
85
86
87tables:
88CREATE TABLE mail (
89 UserTo tinytext NOT NULL,
90 UserFrom tinytext NOT NULL,
91 Subject mediumtext NOT NULL,
92 Message longtext NOT NULL,
93 status text NOT NULL,
94 SentDate text NOT NULL,
95 mail_id int(80) NOT NULL auto_increment,
96 PRIMARY KEY (mail_id)
97) TYPE=MyISAM;
98
99Its easy to embed into your already made member site!
100