I have a php file that is executed every night at midnight. It queries mysql for all user in a table if they have a value of "1" in the alerts field and it returns their email addresses. I am trying to get this file to only email those users. currently i have it working by emailing every single email address in the database $to = $row['email'];
but I cant get it to only send emails to the select users who have signed up for alerts.
<?
$con=mysqli_connect("localhost","root","","DB1");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM users");
##email users their account balances
$sql = mysqli_query("SELECT * FROM users WHERE alerts = '1'");
$recipients = array();
while($row = mysqli_fetch_array($result)){
$recipient[]=$row['email'];
$to = $row['email'];
$subject = "Your account has received a deposit.";
$body = "Hello,
We have added 1 DOGE and .0000001 BTC to your account. Go to www.bitcoinchew.com/Profile to withdrawl. $
if (mail($to, $subject, $body)) {
echo("<p>Email successfully sent!</p>");
} else {
echo("<p>Email delivery failed…</p>");
}
}
?>