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?



   $from =';
   $subject =$_POST['subject'];
   $text =$_POST['body_of_mail'];

   if(empty($subject)) {

   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";
    echo "Email sent to: $to <br /> ";




PHP General Mailing List (
To unsubscribe, visit:

Reply via email to