How can I send an email to each registered user in the database?
In this way I can only send to a user, in this case an email is sent to the last user of bd.
<?php
header("Content-Type: text/html; charset=UTF-8");
$sql = "SELECT * FROM 'user'";
$query = $mysqli->query( $sql );
if( $query->num_rows > 0 ) {
while($row = $query->fetch_assoc()) {
$email[]=$row['email'];
$u=$row['username'];
}
$to = "$email";
$subject = "Assunto";
$txt = "texto exemplo";
$headers = "From: suporte@localhost" . "\r\n" .
"CC: suporte@localhost";
mail($to,$subject,$txt,$headers);
} else {
}
?>