Studying IF statements
| From: | Gary | Date: | Tue, 17 Mar 2009 00:26:03 +0000 |
| Subject: | Studying IF statements | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-290139@lists.php.net to get a copy of this message | ||
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@email.com';
$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);
}
}
?>