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! |
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms. 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!
|
|
|
|
This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”. FREE! Go There Now!
|
|
|
|
Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security. FREE! Go There Now!
|
|
|
|
In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications. FREE! Go There Now!
|
|
|
|
User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges. FREE! Go There Now!
|
|
|
|
Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |