Reading a book on php/mysql (Head First) and the following code is not working, athough I am pretty sure I have it as they say to. Trying to kill a sendmail script if I forget to enter a subject or text in body of email. I am getting the echo, but it is still sending the emails out. What am I missing here? Thanks. Gary <?php $from = emial@xxxxxxxxx'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject)) { if(empty($body_of_mail)){ echo 'You forgot to enter a subject and or text in the body! <br />'; $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = "SELECT * FROM table"; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = "Dear $first_name $last_name,\n$text"; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . '<br />'; } $msg ="Dear $first_name.' '.$last_name\n $text"; mail($to,$subject,$msg,$from); echo "Email sent to: $to <br /> "; mysqli_close($dbc); } } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php