/*I wrote the below php code and got an error when I clicked on the submit button. I should have gotten just the warning in echo when submitting, but I got an error too when I submitted the form. The error that I get in the window once I click on the submit button:
Warning: mysqli_close() expects parameter 1 to be mysqli, null given in /home/content/98/7731198/html/mygiftpackage/sendemail.php on line 39
*/
//The full code that I used for my php file:
<?php
$from = 'contact@doyouknow.com';
$subject = $_POST['subject'];
$text = $_POST['emailmessagefield'];
if ((!empty($subject))&& (!empty($text))){
$dbc = mysqli_connect('hostlocation.db.7731198.hostedresource.com', 'username', 'password', 'databasename')
or die('Error connecting to MySQL server.');
$query = "SELECT * FROM email_list_amy";
$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 />";
}
mysqli_close ($dbc);
}
?>
/*How could the mysqli_close tag be wrong? Does anyone know what I should do? */