I have a database tabe:
ID email
I call this data from the database and post it on a html table
:
<?php
$sql = $link->query("SELECT ...");
while($data = $sql->fetch_object){
?>
<table>
<tr>
<td>
<?=$data->ID?>
</td>
<td>
<?=$data->email?>
</td>
<td>
<input type="checkbox" id="mail_<?=$data->ID?>">
</td>
</tr>
</table>
<?php
}
?>
<input type="button" id="send_mail_button">
The last column has a checkbox. If this chechbox is checked, when I click on send_mail_button
, I'd like to send a mail to every email where the checkbox is checked: to me it's the same if this will be done with an AJAX
call either with a form post
.
I'm able to do this with:
$subject = 'something';
$body = 'hello world!';
foreach($to as $t){
mail($t, $subject, $body);
}
but I'm not able to create an array ($to
) with all the email
address and then retrive every email with a foreach
loop where I send the mails.
How can I do it?