I have my mail form query my database and grab the email from all registered users then a text field for subject, and a textarea for a message. But every time I go to my mail form it emails without having to put in a subject and or message even though in my form I am checking for that. Can someone out their give me some ideas why this is happening. Here is my code:
<?php
include "open_session.php";
if (!isset($mainfile)) include "mainfile.php";
include "config.php";
include "header.php";
$index =0;
$query = "SELECT email FROM members";;
$result = mysql_query ($query);
$row = mysql_fetch_array($result);
while ($row = mysql_fetch_array ($result));
// Send Email Information
$email = $row['email'];
$from = 'admin@yoursite.com';
if (!isset($_POST['send'])) {
?>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend><b>Enter your information in the form below:</b></legend></legend>
<p><b>Subject:</b><br /> <input type="text" name="subject" size="30" maxlength="30" /></p>
<p><b>Message:</b><br /> <textarea name="message" rows="15" cols="50"></textarea></p>
</fieldset><br />
<div align="center"> <input type="submit" name="send" value="Send" /></div>
</body>
</html>
<?php
if (strlen($_POST['subject'])) > 0) {
$subject = TRUE;
} else {
$subject = FALSE;
echo '<p><b>You forgot to enter a subject!</b></p>';
}
if (strlen($_POST['message'])) > 0) {
$message = TRUE;
} else {
$message = FALSE;
echo '<p><b>You forgot to type in a message.</b></p>';
}
if (mail($email, $_POST['subject'], $_POST['message'], "FROM: $from")) {
echo '<p align="right"><a href=admin.php>Back to Admin Menu</a></p>';
echo '<p align="center"><b>Your email has been sent!</b></p>';
} else {
echo '<p><b>Due to errors your email was not sent. Please verify everything was entered correctly.</b></p>';
}
?>
<?php
include "footer.php";
?>