单击复选框后创建一组电子邮件



我目前正在我的管理门户中创建一个电子邮件部分。我已经将其全部配置为能够发送到多封电子邮件。现在我想自动化这个过程。

一旦管理员选中"所有用户"复选框,我希望它通过电子邮件发送给所有用户。这需要通过创建一组用户来完成。我有它的代码,那就是

<?php
$result = mysqli_query($conn, "SELECT email FROM cadets ORDER BY id ASC");
$cadetEmailList = array();
while($row = mysqli_fetch_array($result)) {
array_push($cadetEmailList, $row['email']);
} 
print_r($cadetEmailList)
?>

现在我有了一系列的电子邮件。选择"所有用户"框后,如何使用此数组作为值?

<tr>
<th>Recipients List</th>
</tr>
</thead>
<tr><td><input type="checkbox" id="basic_checkbox_2" class="filled-in" name="all_cadets" /><label for="basic_checkbox_2">All Cadets</label></td>

我的短手逻辑是。。。如果选中复选框,则将所有电子邮件推送到数组变量中。

$mailAllCadets=isset($_POST['all_cadets']) ? $_POST['all_cadets'] : "";
if ($mailAllCadets) {
$result = mysqli_query($conn, "SELECT email FROM cadets ORDER BY id ASC");
$mailList = array();
while($row = mysqli_fetch_array($result)) {
array_push($mailList, $row['email']);
$mailList = preg_replace("/[s-]+/", " ", $mailList);
$mailList = preg_replace("/[s_]/", ";", $mailList);
}
if (strpos($mailTo, ";") !== false) {
$mailTo = explode(";", $mailTo);
}
var_dump($mailList);
for ($i = 0; $i < sizeof($mailList); $i++) {
//  $mail->AddAddress($mailList[$i]);
}
}

最新更新