I have a simple form with only one submit button.
When i write email in to $to = 'example@email.com'; everything works fine.
But when i do select from database, i want to put email from db. to variable ($to) - mail function ignoring and will not send an email to any address. Is there any way how to put emails from database to variable?
Thanks a lot.
<form method="POST">
<input type="submit" name="submit" value="SEND EMAIL">
</form>
<?php
$query = "select * from emails_db";
$result = mysqli_query($link,$query);
if ($result-> num_rows > 0) {
while ($row = $result-> fetch_assoc()) {
if(isset($_POST['submit'])) {
$to = $row['email'];
$subject = 'TEST EMAIL';
$message = 'Test message';
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=UTF-8';
$headers[] = 'To: <example@email.com>';
$headers[] = 'From: TEST ADMIN EMAIL <exampleadmin@email.com>';
mail($to, $subject, $message, $headers));
}
}
?>