I have this php code:
<?php
//include database
include 'db.php';
//grab the emails from the database
$sql = "SELECT email FROM `emails`";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_array($result, MYSQL_ASSOC)){
// update the database
//sanitinzw
$row = mysqli_real_escape_string($con, $row['email']);
//mail the emails
$to = $row;
$subject = 'HELLOO';
$message = 'alooooo';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
?>
It works just fine; however, when I add a query to it only the first email in my database is sent here it what it looks like.
<?php
//include database
include 'db.php';
//grab the emails from the database
$sql = "SELECT email FROM `emails`";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_array($result, MYSQL_ASSOC)){
// update the database
//sanitinzw
$row = mysqli_real_escape_string($con, $row['email']);
//mail the emails
$to = $row;
$subject = 'hello';
$message = 'aloooooo';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
$sql = "UPDATE `emails` SET times_used = times_used + 1 WHERE email = '$row' ";
$result = mysqli_query($con, $sql);
}
?>
for some reason it only updating the first email in the database and when I try to echo out $row only the first email is echoe'd
Thanks for the help