Jump to content

Recommended Posts

I'm working on my messaging system and when you reply I have it add RE: to the subject, however now there're messages that're RE:RE:RE:RE:RE:RE:___ etc, Is there a way for it to tell it to add RE: only if it's not there?

 

<?php
session_start();
include("header.php");
include("members.php");

$a = $_GET['action'];
$u = $_SESSION['ELv2'];
$id = $_GET['id'];
?>

<h2>Message Center</h2>

<input type='button' value='Send a New Message!' onClick='parent.location="/mail.php?action=newmsg"' class='text_box' style='width: 200px' alt='Send a message!' title='Send a message!'>

<input type='button' value='Inbox!' onClick='parent.location="/mail.php?action=inbox"' class='text_box' style='width: 200px' alt='View your recieved mail!' title='View your recieved mail!'>

<input type='button' value='Outbox!' onClick='parent.location="/mail.php?action=outbox"' class='text_box' style='width: 200px' alt='View mail you have sent!' title='View mail you have sent!'>


<?php
switch($a)
{
case "inbox":
	print "<br><h1>Inbox</h1><p>
	<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" bgcolor=\"#000000\">
	<tr>
	<Td bgcolor=\"#dddddd\" class=\"text_box\">Subject</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">From</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Date</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Status</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Actions</td>
	</tr>";   
	$query = "SELECT * FROM `messages` WHERE `to` = '{$u}' AND `site` = '$Z'  ORDER BY `id` DESC";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	while($row = mysql_fetch_array($sql)) {
		extract($row);
		print "<tr>
		<td bgcolor=\"#ffffff\" class=\"other\">" . $subject . "</td>
		<td bgcolor=\"#ffffff\" class=\"other\">" . $from . "</td>
		<td bgcolor=\"#ffffff\" class=\"other\">" . $date . "</td>
		<td bgcolor=\"#ffffff\" class=\"other\">" . $status . "</td>
		<td bgcolor=\"#ffffff\" class=\"other\"><a href=\"mail.php?action=sview&id=" . $id . "\">Read - <a href=\"mail.php?action=delete&id=" . $id . "\">Delete</td>
		</tr>";    
	}
	print "</table>";
break;
case "outbox":
	print "<br><h1>Outbox</h2><p>
	<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" bgcolor=\"#000000\">
	<tr>
	<Td bgcolor=\"#dddddd\" class=\"text_box\">Subject</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">To</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Date</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Status</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Actions</td>
	</tr>";   
	$query = "SELECT * FROM `messages` WHERE `from` = '{$u}' AND `site` = '$Z'  ORDER BY `id` DESC";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	while($row = mysql_fetch_array($sql)) {
		extract($row);		
		print "<tr>
		<td bgcolor=\"#ffffff\" class=\"other\">$subject</td>
		<td bgcolor=\"#ffffff\" class=\"other\">$to</td>
		<td bgcolor=\"#ffffff\" class=\"other\">$date</td>
		<td bgcolor=\"#ffffff\" class=\"other\">$status</td>
		<td bgcolor=\"#ffffff\" class=\"other\"><a href=\"mail.php?action=view&id=$id\">Read - <a href=\"mail.php?action=delete&id=$id\">Delete</td>
		</tr>";    
	}
	print "</table>";
break;
case "delete":
	$del = mysql_query("DELETE FROM `messages` WHERE `id` = '$id' AND `site` = '$Z'");

	if($del)
	{
		Header("Location: mail.php?action=inbox");
	}
	else {
		print mysql_error();
	}
break;
case "view":
	$update = mysql_query("UPDATE `messages` SET `status`='read' WHERE `id`='$id' AND `site`='$Z'");

	$query = "SELECT * FROM `messages` WHERE `id`='$id' AND `site` = '$Z'";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	while($row = mysql_fetch_array($sql))
	{
		extract($row);		
		print "<h2>$subject</h2><p>
		To: $to<br>
		From: $from<br>
		Date: $date<p>
		<form action=\"mail.php?action=sendmsg\" method=\"post\">
		<input type=\"hidden\" name=\"to\" value=\"$from\" class=\"text_box\">
		<input type=\"hidden\" name=\"subject\" value=\"RE: $subject\" class=\"text_box\">
		<input type=\"hidden\" name=\"type\" value=\"2\" class=\"text_box\">
		Message:<br>
		<textarea rows=\"6\" cols=\"60\" nowrap name=\"message\" class=\"text_box\">
		$body
		</textarea><p>";
	}
break;

case "sendmsg":
	if($_POST['type'] == "1")
	{
		$headers  = "MIME-Version: 1.0\r\n";
		$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
		$headers .= "To: ".trim($_POST['to'])."\r\n";
		$headers .= "From: ".trim($_POST['from'])."\r\n";
		$headers .= "Reply-To: ".trim($email)."\r\nnew;reply-to: ".trim($email)."\r\n";
		@mail(trim($_POST['to']), trim($_POST['subject']), $_POST['message'], $headers);
		echo("Mail sent to ".trim($_POST['to']) );
	}elseif ($_POST['type'] == "2")		{
		$subject = $_POST['subject'];
		$message = $_POST['message'];
		$date = date("m/d/y");
		$status = "unread";
		$to = $_POST['to'];

		if($subject && $to && $message) {
			$insert = mysql_query("INSERT INTO `messages` (`site`, `subject`, `body`, `status`, `date`, `to`, `from`) VALUES('$Z', '$subject', '$message', '$status', '$date', '$to', '$u')");
			if($insert) {
				print "<h2>Message Sent</h2><p>
				Your message has been sent!<P>";?>
				<input type='button' value='Back to Inbox!' onClick='parent.location="/mail.php?action=inbox"' class='text_box' style='width: 200px' alt='Go back to the inbox!' title='Go back to the inbox!'>
                <?php
			}else {
				print mysql_error();
			}
		} else {
			print "Subject, To User, and Message are required!";
		}      
	}
break;
case "sview":
	$update = mysql_query("UPDATE `messages` SET status = 'read' WHERE `id`='$id' AND `site`= '$Z'");
	$query = "SELECT * FROM `messages` WHERE `id`='$id' AND `site` = '$Z'";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	while($row = mysql_fetch_array($sql))
	{
   		extract($row);
		print "<h2>$subject</h2><p>
		To: $to

		<br>From: $from 

		<br>Date: $date<p>
		$body<p>

		<form action=\"mail.php?action=sendmsg\" method=\"post\">
		<input type=\"hidden\" name=\"to\" value=\"$from\" class=\"text_box\">
		<input type=\"hidden\" name=\"type\" value=\"2\" class=\"text_box\">
		<input type=\"hidden\" name=\"subject\" value=\"RE: $subject\" class=\"text_box\">
		Reply:<br>

		<textarea rows=\"6\" cols=\"60\" nowrap name=\"message\" class=\"text_box\">


		<p><p>Original Message

		---------------------------

		To: $to

		From: $from 

		Date: $date

		Message:

		$body</textarea><p>
		<input type=\"submit\" value=\" Send Reply \" class=\"text_box\"></form>";
	}
break;

default:
	$query = "SELECT count(*) as msgs FROM `messages` WHERE `to` = '$u' AND `site` = '$Z' ";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	$msg = mysql_fetch_array($sql);
	echo "You have {$msg['msgs']} messages"; 
	echo "<h1>Send Message</h1><p>
		<form action=\"mail.php?action=sendmsg\" method=\"post\">";
	echo "<input type=\"radio\" name=\"type\" value=\"1\" class=\"text_box\" alt=\"Click here if you are sending your message outside this site via email\" title=\"Click here if you are sending your message outside this site via email\"> Email

		<input type=\"radio\" name=\"type\" value=\"2\" checked class=\"text_box\" alt=\"Click here if you are sending a message within this site and NOT via email!\" title=\"Click here if you are sending a message within this site and NOT via email!\"> Private Message
		<br>
		To:
		<br>
		<input type=\"text\" name=\"to\" class=\"text_box\" alt=\"Who do you want to send your message to?\" title=\"Who do you want to send your message to?\"><p>
		From:<br>

		<select name=\"from\" size=\"1\" class=\"text_box\" alt=\"Please choose where your sending from!\" title=\"Please choose where you are sending from!\">";
	$sql = mysql_query("SELECT * FROM `members` WHERE `username`='$u'");
	while($row = mysql_fetch_array($sql))
	{
		$us = $row["username"];
		print "<option value=\"$us\">$us</option>
		<option value=\"$us@eaglelegend.com\">$us@eaglelegend.com</option>";
	}
	print "</select><p>   
			   
			Subject:<br>

			<input type=\"text\" name=\"subject\" size=\"30\" class=\"text_box\" alt=\"What is the title/subject of your message?\" title=\"What is the title/subject of your message?\"><p>
			Message:<br>

			<textarea rows=\"6\" cols=\"60\" nowrap name=\"message\" class=\"text_box\" alt=\"Please enter your message!\" title=\"Please enter your message!\"></textarea><p>
			<input type=\"submit\" value=\" Send Message \" class=\"text_box\" alt=\"Click here to send your message!\" title=\"Click here to send your message!\"></form>";   

	#$query = "SELECT `email` FROM `members` WHERE `username`='".mysql_escape_string($username)."' LIMIT 1";
break;
}
include("footer.php");
?>

 

Help is appreciated!

Link to comment
https://forums.phpfreaks.com/topic/106311-simple-question/
Share on other sites

 

note the code

$subject = (substr($subject,0,3)=="RE:")$subject:"RE: $subject";

 

<?php
session_start();
include("header.php");
include("members.php");

$a = $_GET['action'];
$u = $_SESSION['ELv2'];
$id = $_GET['id'];
?>

<h2>Message Center</h2>

<input type='button' value='Send a New Message!' onClick='parent.location="/mail.php?action=newmsg"' class='text_box' style='width: 200px' alt='Send a message!' title='Send a message!'>

<input type='button' value='Inbox!' onClick='parent.location="/mail.php?action=inbox"' class='text_box' style='width: 200px' alt='View your recieved mail!' title='View your recieved mail!'>

<input type='button' value='Outbox!' onClick='parent.location="/mail.php?action=outbox"' class='text_box' style='width: 200px' alt='View mail you have sent!' title='View mail you have sent!'>


<?php
switch($a)
{
case "inbox":
	print "<br><h1>Inbox</h1><p>
	<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" bgcolor=\"#000000\">
	<tr>
	<Td bgcolor=\"#dddddd\" class=\"text_box\">Subject</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">From</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Date</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Status</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Actions</td>
	</tr>";   
	$query = "SELECT * FROM `messages` WHERE `to` = '{$u}' AND `site` = '$Z'  ORDER BY `id` DESC";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	while($row = mysql_fetch_array($sql)) {
		extract($row);
		print "<tr>
		<td bgcolor=\"#ffffff\" class=\"other\">" . $subject . "</td>
		<td bgcolor=\"#ffffff\" class=\"other\">" . $from . "</td>
		<td bgcolor=\"#ffffff\" class=\"other\">" . $date . "</td>
		<td bgcolor=\"#ffffff\" class=\"other\">" . $status . "</td>
		<td bgcolor=\"#ffffff\" class=\"other\"><a href=\"mail.php?action=sview&id=" . $id . "\">Read - <a href=\"mail.php?action=delete&id=" . $id . "\">Delete</td>
		</tr>";    
	}
	print "</table>";
break;
case "outbox":
	print "<br><h1>Outbox</h2><p>
	<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" bgcolor=\"#000000\">
	<tr>
	<Td bgcolor=\"#dddddd\" class=\"text_box\">Subject</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">To</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Date</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Status</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Actions</td>
	</tr>";   
	$query = "SELECT * FROM `messages` WHERE `from` = '{$u}' AND `site` = '$Z'  ORDER BY `id` DESC";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	while($row = mysql_fetch_array($sql)) {
		extract($row);		
		print "<tr>
		<td bgcolor=\"#ffffff\" class=\"other\">$subject</td>
		<td bgcolor=\"#ffffff\" class=\"other\">$to</td>
		<td bgcolor=\"#ffffff\" class=\"other\">$date</td>
		<td bgcolor=\"#ffffff\" class=\"other\">$status</td>
		<td bgcolor=\"#ffffff\" class=\"other\"><a href=\"mail.php?action=view&id=$id\">Read - <a href=\"mail.php?action=delete&id=$id\">Delete</td>
		</tr>";    
	}
	print "</table>";
break;
case "delete":
	$del = mysql_query("DELETE FROM `messages` WHERE `id` = '$id' AND `site` = '$Z'");

	if($del)
	{
		Header("Location: mail.php?action=inbox");
	}
	else {
		print mysql_error();
	}
break;
case "view":
	$update = mysql_query("UPDATE `messages` SET `status`='read' WHERE `id`='$id' AND `site`='$Z'");

	$query = "SELECT * FROM `messages` WHERE `id`='$id' AND `site` = '$Z'";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	while($row = mysql_fetch_array($sql))
	{
		extract($row);
		$subject = (substr($subject,0,3)=="RE:")$subject:"RE: $subject";
		print "<h2>$subject</h2><p>
		To: $to<br>
		From: $from<br>
		Date: $date<p>
		<form action=\"mail.php?action=sendmsg\" method=\"post\">
		<input type=\"hidden\" name=\"to\" value=\"$from\" class=\"text_box\">
		<input type=\"hidden\" name=\"subject\" value=\"$subject\" class=\"text_box\">
		<input type=\"hidden\" name=\"type\" value=\"2\" class=\"text_box\">
		Message:<br>
		<textarea rows=\"6\" cols=\"60\" nowrap name=\"message\" class=\"text_box\">
		$body
		</textarea><p>";
	}
break;

case "sendmsg":
	if($_POST['type'] == "1")
	{
		$headers  = "MIME-Version: 1.0\r\n";
		$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
		$headers .= "To: ".trim($_POST['to'])."\r\n";
		$headers .= "From: ".trim($_POST['from'])."\r\n";
		$headers .= "Reply-To: ".trim($email)."\r\nnew;reply-to: ".trim($email)."\r\n";
		@mail(trim($_POST['to']), trim($_POST['subject']), $_POST['message'], $headers);
		echo("Mail sent to ".trim($_POST['to']) );
	}elseif ($_POST['type'] == "2")		{
		$subject = $_POST['subject'];
		$message = $_POST['message'];
		$date = date("m/d/y");
		$status = "unread";
		$to = $_POST['to'];

		if($subject && $to && $message) {
			$insert = mysql_query("INSERT INTO `messages` (`site`, `subject`, `body`, `status`, `date`, `to`, `from`) VALUES('$Z', '$subject', '$message', '$status', '$date', '$to', '$u')");
			if($insert) {
				print "<h2>Message Sent</h2><p>
				Your message has been sent!<P>";?>
				<input type='button' value='Back to Inbox!' onClick='parent.location="/mail.php?action=inbox"' class='text_box' style='width: 200px' alt='Go back to the inbox!' title='Go back to the inbox!'>
                <?php
			}else {
				print mysql_error();
			}
		} else {
			print "Subject, To User, and Message are required!";
		}      
	}
break;
case "sview":
	$update = mysql_query("UPDATE `messages` SET status = 'read' WHERE `id`='$id' AND `site`= '$Z'");
	$query = "SELECT * FROM `messages` WHERE `id`='$id' AND `site` = '$Z'";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	while($row = mysql_fetch_array($sql))
	{
   		extract($row);
		$subject = (substr($subject,0,3)=="RE:")$subject:"RE: $subject";
		print "<h2>$subject</h2><p>
		To: $to

		<br>From: $from 

		<br>Date: $date<p>
		$body<p>

		<form action=\"mail.php?action=sendmsg\" method=\"post\">
		<input type=\"hidden\" name=\"to\" value=\"$from\" class=\"text_box\">
		<input type=\"hidden\" name=\"type\" value=\"2\" class=\"text_box\">
		<input type=\"hidden\" name=\"subject\" value=\"$subject\" class=\"text_box\">
		Reply:<br>

		<textarea rows=\"6\" cols=\"60\" nowrap name=\"message\" class=\"text_box\">


		<p><p>Original Message

		---------------------------

		To: $to

		From: $from 

		Date: $date

		Message:

		$body</textarea><p>
		<input type=\"submit\" value=\" Send Reply \" class=\"text_box\"></form>";
	}
break;

default:
	$query = "SELECT count(*) as msgs FROM `messages` WHERE `to` = '$u' AND `site` = '$Z' ";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	$msg = mysql_fetch_array($sql);
	echo "You have {$msg['msgs']} messages"; 
	echo "<h1>Send Message</h1><p>
		<form action=\"mail.php?action=sendmsg\" method=\"post\">";
	echo "<input type=\"radio\" name=\"type\" value=\"1\" class=\"text_box\" alt=\"Click here if you are sending your message outside this site via email\" title=\"Click here if you are sending your message outside this site via email\"> Email

		<input type=\"radio\" name=\"type\" value=\"2\" checked class=\"text_box\" alt=\"Click here if you are sending a message within this site and NOT via email!\" title=\"Click here if you are sending a message within this site and NOT via email!\"> Private Message
		<br>
		To:
		<br>
		<input type=\"text\" name=\"to\" class=\"text_box\" alt=\"Who do you want to send your message to?\" title=\"Who do you want to send your message to?\"><p>
		From:<br>

		<select name=\"from\" size=\"1\" class=\"text_box\" alt=\"Please choose where your sending from!\" title=\"Please choose where you are sending from!\">";
	$sql = mysql_query("SELECT * FROM `members` WHERE `username`='$u'");
	while($row = mysql_fetch_array($sql))
	{
		$us = $row["username"];
		print "<option value=\"$us\">$us</option>
		<option value=\"$us@eaglelegend.com\">$us@eaglelegend.com</option>";
	}
	print "</select><p>   
			   
			Subject:<br>

			<input type=\"text\" name=\"subject\" size=\"30\" class=\"text_box\" alt=\"What is the title/subject of your message?\" title=\"What is the title/subject of your message?\"><p>
			Message:<br>

			<textarea rows=\"6\" cols=\"60\" nowrap name=\"message\" class=\"text_box\" alt=\"Please enter your message!\" title=\"Please enter your message!\"></textarea><p>
			<input type=\"submit\" value=\" Send Message \" class=\"text_box\" alt=\"Click here to send your message!\" title=\"Click here to send your message!\"></form>";   

	#$query = "SELECT `email` FROM `members` WHERE `username`='".mysql_escape_string($username)."' LIMIT 1";
break;
}
include("footer.php");
?>

Link to comment
https://forums.phpfreaks.com/topic/106311-simple-question/#findComment-544818
Share on other sites

ooops

 

edit:

$subject = (substr($subject,0,3)=="RE:")?$subject:"RE: $subject";

<?php
session_start();
include("header.php");
include("members.php");

$a = $_GET['action'];
$u = $_SESSION['ELv2'];
$id = $_GET['id'];
?>

<h2>Message Center</h2>

<input type='button' value='Send a New Message!' onClick='parent.location="/mail.php?action=newmsg"' class='text_box' style='width: 200px' alt='Send a message!' title='Send a message!'>

<input type='button' value='Inbox!' onClick='parent.location="/mail.php?action=inbox"' class='text_box' style='width: 200px' alt='View your recieved mail!' title='View your recieved mail!'>

<input type='button' value='Outbox!' onClick='parent.location="/mail.php?action=outbox"' class='text_box' style='width: 200px' alt='View mail you have sent!' title='View mail you have sent!'>


<?php
switch($a)
{
case "inbox":
	print "<br><h1>Inbox</h1><p>
	<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" bgcolor=\"#000000\">
	<tr>
	<Td bgcolor=\"#dddddd\" class=\"text_box\">Subject</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">From</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Date</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Status</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Actions</td>
	</tr>";   
	$query = "SELECT * FROM `messages` WHERE `to` = '{$u}' AND `site` = '$Z'  ORDER BY `id` DESC";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	while($row = mysql_fetch_array($sql)) {
		extract($row);
		print "<tr>
		<td bgcolor=\"#ffffff\" class=\"other\">" . $subject . "</td>
		<td bgcolor=\"#ffffff\" class=\"other\">" . $from . "</td>
		<td bgcolor=\"#ffffff\" class=\"other\">" . $date . "</td>
		<td bgcolor=\"#ffffff\" class=\"other\">" . $status . "</td>
		<td bgcolor=\"#ffffff\" class=\"other\"><a href=\"mail.php?action=sview&id=" . $id . "\">Read - <a href=\"mail.php?action=delete&id=" . $id . "\">Delete</td>
		</tr>";    
	}
	print "</table>";
break;
case "outbox":
	print "<br><h1>Outbox</h2><p>
	<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" bgcolor=\"#000000\">
	<tr>
	<Td bgcolor=\"#dddddd\" class=\"text_box\">Subject</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">To</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Date</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Status</td>
	<td bgcolor=\"#dddddd\" class=\"text_box\">Actions</td>
	</tr>";   
	$query = "SELECT * FROM `messages` WHERE `from` = '{$u}' AND `site` = '$Z'  ORDER BY `id` DESC";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	while($row = mysql_fetch_array($sql)) {
		extract($row);		
		print "<tr>
		<td bgcolor=\"#ffffff\" class=\"other\">$subject</td>
		<td bgcolor=\"#ffffff\" class=\"other\">$to</td>
		<td bgcolor=\"#ffffff\" class=\"other\">$date</td>
		<td bgcolor=\"#ffffff\" class=\"other\">$status</td>
		<td bgcolor=\"#ffffff\" class=\"other\"><a href=\"mail.php?action=view&id=$id\">Read - <a href=\"mail.php?action=delete&id=$id\">Delete</td>
		</tr>";    
	}
	print "</table>";
break;
case "delete":
	$del = mysql_query("DELETE FROM `messages` WHERE `id` = '$id' AND `site` = '$Z'");

	if($del)
	{
		Header("Location: mail.php?action=inbox");
	}
	else {
		print mysql_error();
	}
break;
case "view":
	$update = mysql_query("UPDATE `messages` SET `status`='read' WHERE `id`='$id' AND `site`='$Z'");

	$query = "SELECT * FROM `messages` WHERE `id`='$id' AND `site` = '$Z'";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	while($row = mysql_fetch_array($sql))
	{
		extract($row);
		$subject = (substr($subject,0,3)=="RE:")?$subject:"RE: $subject";
		print "<h2>$subject</h2><p>
		To: $to<br>
		From: $from<br>
		Date: $date<p>
		<form action=\"mail.php?action=sendmsg\" method=\"post\">
		<input type=\"hidden\" name=\"to\" value=\"$from\" class=\"text_box\">
		<input type=\"hidden\" name=\"subject\" value=\"$subject\" class=\"text_box\">
		<input type=\"hidden\" name=\"type\" value=\"2\" class=\"text_box\">
		Message:<br>
		<textarea rows=\"6\" cols=\"60\" nowrap name=\"message\" class=\"text_box\">
		$body
		</textarea><p>";
	}
break;

case "sendmsg":
	if($_POST['type'] == "1")
	{
		$headers  = "MIME-Version: 1.0\r\n";
		$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
		$headers .= "To: ".trim($_POST['to'])."\r\n";
		$headers .= "From: ".trim($_POST['from'])."\r\n";
		$headers .= "Reply-To: ".trim($email)."\r\nnew;reply-to: ".trim($email)."\r\n";
		@mail(trim($_POST['to']), trim($_POST['subject']), $_POST['message'], $headers);
		echo("Mail sent to ".trim($_POST['to']) );
	}elseif ($_POST['type'] == "2")		{
		$subject = $_POST['subject'];
		$message = $_POST['message'];
		$date = date("m/d/y");
		$status = "unread";
		$to = $_POST['to'];

		if($subject && $to && $message) {
			$insert = mysql_query("INSERT INTO `messages` (`site`, `subject`, `body`, `status`, `date`, `to`, `from`) VALUES('$Z', '$subject', '$message', '$status', '$date', '$to', '$u')");
			if($insert) {
				print "<h2>Message Sent</h2><p>
				Your message has been sent!<P>";?>
				<input type='button' value='Back to Inbox!' onClick='parent.location="/mail.php?action=inbox"' class='text_box' style='width: 200px' alt='Go back to the inbox!' title='Go back to the inbox!'>
                <?php
			}else {
				print mysql_error();
			}
		} else {
			print "Subject, To User, and Message are required!";
		}      
	}
break;
case "sview":
	$update = mysql_query("UPDATE `messages` SET status = 'read' WHERE `id`='$id' AND `site`= '$Z'");
	$query = "SELECT * FROM `messages` WHERE `id`='$id' AND `site` = '$Z'";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	while($row = mysql_fetch_array($sql))
	{
   		extract($row);
		$subject = (substr($subject,0,3)=="RE:")?$subject:"RE: $subject";
		print "<h2>$subject</h2><p>
		To: $to

		<br>From: $from 

		<br>Date: $date<p>
		$body<p>

		<form action=\"mail.php?action=sendmsg\" method=\"post\">
		<input type=\"hidden\" name=\"to\" value=\"$from\" class=\"text_box\">
		<input type=\"hidden\" name=\"type\" value=\"2\" class=\"text_box\">
		<input type=\"hidden\" name=\"subject\" value=\"$subject\" class=\"text_box\">
		Reply:<br>

		<textarea rows=\"6\" cols=\"60\" nowrap name=\"message\" class=\"text_box\">


		<p><p>Original Message

		---------------------------

		To: $to

		From: $from 

		Date: $date

		Message:

		$body</textarea><p>
		<input type=\"submit\" value=\" Send Reply \" class=\"text_box\"></form>";
	}
break;

default:
	$query = "SELECT count(*) as msgs FROM `messages` WHERE `to` = '$u' AND `site` = '$Z' ";
	$sql = mysql_query($query) or die("MySQL Error in query: ".$query."<br />".mysql_error());
	$msg = mysql_fetch_array($sql);
	echo "You have {$msg['msgs']} messages"; 
	echo "<h1>Send Message</h1><p>
		<form action=\"mail.php?action=sendmsg\" method=\"post\">";
	echo "<input type=\"radio\" name=\"type\" value=\"1\" class=\"text_box\" alt=\"Click here if you are sending your message outside this site via email\" title=\"Click here if you are sending your message outside this site via email\"> Email

		<input type=\"radio\" name=\"type\" value=\"2\" checked class=\"text_box\" alt=\"Click here if you are sending a message within this site and NOT via email!\" title=\"Click here if you are sending a message within this site and NOT via email!\"> Private Message
		<br>
		To:
		<br>
		<input type=\"text\" name=\"to\" class=\"text_box\" alt=\"Who do you want to send your message to?\" title=\"Who do you want to send your message to?\"><p>
		From:<br>

		<select name=\"from\" size=\"1\" class=\"text_box\" alt=\"Please choose where your sending from!\" title=\"Please choose where you are sending from!\">";
	$sql = mysql_query("SELECT * FROM `members` WHERE `username`='$u'");
	while($row = mysql_fetch_array($sql))
	{
		$us = $row["username"];
		print "<option value=\"$us\">$us</option>
		<option value=\"$us@eaglelegend.com\">$us@eaglelegend.com</option>";
	}
	print "</select><p>   
			   
			Subject:<br>

			<input type=\"text\" name=\"subject\" size=\"30\" class=\"text_box\" alt=\"What is the title/subject of your message?\" title=\"What is the title/subject of your message?\"><p>
			Message:<br>

			<textarea rows=\"6\" cols=\"60\" nowrap name=\"message\" class=\"text_box\" alt=\"Please enter your message!\" title=\"Please enter your message!\"></textarea><p>
			<input type=\"submit\" value=\" Send Message \" class=\"text_box\" alt=\"Click here to send your message!\" title=\"Click here to send your message!\"></form>";   

	#$query = "SELECT `email` FROM `members` WHERE `username`='".mysql_escape_string($username)."' LIMIT 1";
break;
}
include("footer.php");
?>

Link to comment
https://forums.phpfreaks.com/topic/106311-simple-question/#findComment-544828
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.