Forum Moderators: coopster
<?php
include "../connect.php"; //connection string
include("../include/session.php");
print "<link rel='stylesheet' href='style.css' type='text/css'>";
print "<table class='maintables'>";
print "<tr class='headline'><td>Post a message</td></tr>";
print "<tr class='maintables'><td>";
// Write out our query.
$query = "SELECT username,email FROM users";
// Execute it, or return the error message if there's a problem.
$result = mysql_query($query) or die(mysql_error());
$dropdown = "<select name='username'>";
while($row = mysql_fetch_assoc($result)) {
$dropdown .= "\r\n<option value='{$row['username']}'>{$row['username']}</option>";
}
$dropdown .= "\r\n</select>";
if(isset($_POST['submit']))
{
$name=$session->username;
$yourpost=$_POST['yourpost'];
$subject=$_POST['subject'];
$to=$_POST['username'];
$tom1=$_POST['email'];
$to666 = '$tom1';
//define the subject of the email
//define the message to be sent. Each line should be separated with \n
$message666 = "new message from $name\nMessage:\n$yourpost\n\nwww.#*$!#*$!xx";
//define the headers we want passed. Note that they are separated with \r\n
$headers666 = "From: office@#*$!#*$!x\r\nReply-To: office@#*$!#*$!x";
//send the email
$mail_sent = @mail( $to666, $subject, $message666, $headers666 );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent\n" : "Mail failed";
if(strlen($name)<1)
{
print "You did not type in a name."; //no name entered
}
else if(strlen($yourpost)<1)
{
print "You did not type in a post."; //no post entered
}
else if(strlen($subject)<1)
{
print "You did not enter a subject."; //no subject entered
}
else
{
$thedate=date("U"); //get unix timestamp
$displaytime=date("F j, Y, g:i a");
//we now strip HTML injections
$subject=strip_tags($subject);
$name=strip_tags($name);
$yourpost=strip_tags($yourpost);
$to=strip_tags($to);
print "Message posted, go back to <A href='forum.php'>Forum</a>.";
}
}
else
{
print "<form action='mail.php' method='post'>";
print "Your name:<br>";
print "$session->username<br>";
print "User to send to:<br>";
print "$dropdown<br>";
print "Subject:<br>";
print "<input type='text' name='subject' size='20'><br>";
print "Your message:<br>";
print "<textarea name='yourpost' rows='5' cols='40'></textarea><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
print "</td></tr></table>";
?>
// Set this to 1 to print out values and NOT send mail
// this is the printout I mentioned. See $debug below
$debug = null;
$errors = null;
if(strlen($name)<1) {
$errors .= "<li>You did not type in a name.</li>"; // note the list tags
}
if(strlen($yourpost)<1) {
$errors .= "<li>You did not type in a post.</li>";
}
if(strlen($subject)<1) {
$errors .= "<li>You did not enter a subject.</li>";
}
//
if ($errors) {
print "<p>Your post has the following errors, please try again:</p><ul>$errors</ul>";
}
else {
$thedate=date("U"); //get unix timestamp
$displaytime=date("F j, Y, g:i a");
$name=$session->username;
$yourpost=strip_tags($_POST['yourpost']);
$subject=strip_tags($_POST['subject']);
$to=strip_tags($_POST['username']);
$tom1=strip_tags($_POST['email']);
$message666 = "new message from $name\nMessage:\n$yourpost\n\nwww.#*$!#*$!xx";
$headers666 = "From: $tom1\r\n";
if ($debug) {
print "<p>Mail to: $to From: $tom1 Headers $headers666 Subject: $subject Name: $name message: $message666</p>";
}
else {
if (mail( $to, $subject, $message666, $headers666 )) {
print "<p>Message posted, go back to <a href=\"forum.php\">Forum</a>.</p>";
}
else { print "<p>Mail error: mail could not be sent.</p>"; }
}
}