With this code you can easily add a internal mail system to your site the varibles are easy to change!
By : cscartman
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!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Discussion Board Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
|
|
|
|
Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points. FREE! Go There Now!
|
|
|
|
With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential. FREE! Go There Now!
|
|
|
|
Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository. FREE! Go There Now!
|
|
|
|
Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems. FREE! Go There Now!
|
|
|
|
As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change. FREE! Go There Now!
|
|
|
|
Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered! FREE! Go There Now!
|
|
|
|
IBM Enterprise Modernization solutions help organizations evolve core IT systems towards modern architectures and technologies—reducing the burden of maintenance and freeing up resources to develop new business requirements and capabilities. With the IBM Enterprise Modernization Sandbox for System z you can evaluate IBM Enterprise Modernization solutions focused on five key areas: Assets, Architectures, Skills, Processes and Infrastructures, and Investment. Each solution is based upon real customer experiences and offers a proven path to get you started with your modernization projects. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |