基本上我想向几个收件人发送相同的邮件,如果电子邮件已发送给该用户,我希望它注册一个复选框;如果不是,则要取消选中(用户必须选中复选框以便注册)我找不到办法,所以当用户检查复选框时,它会在数据库中更新。我尝试过使用Ajax,但我不知道如何正确使用它。我需要一些认真的帮助。 我的index.php
<?php
include_once 'dbh.php';
include_once 'contact.php';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="/css/reset.css">
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<br>
<div class="tabela">
<table class="scroll">
<thead>
<tr>
<th>                        
                            
          Nome da Escola                 
                           
          </th>
<th>              Email Geral da Escola         
        </th>
<th>   Enviado</th>
</tr>
</thead>
<tbody>
<?php
$execItems = $conn->query("SELECT Nome,EmailGeral,Enviado FROM escolas");
while($infoItems = $execItems->fetch_array()){
echo "
<tr>
<td>".$infoItems['Nome']."</td>
<td>".$infoItems['EmailGeral']."</td>
<td><input type=\"checkbox\"".($infoItems['Enviado']?' checked':'checked')."\" /></td>
</tr>
";
}
?>
</tbody>
</table>
<div class="mail">
<form action="" method="post">
<button class="butao" type="button" onclick="emailNext();">Adicionar Email</button>
<div id="addEmail"></div>
<script>
function emailNext() {
var nextEmail, inside_where;
nextEmail = document.createElement('input');
nextEmail.type = 'text';
nextEmail.name = 'email[]';
nextEmail.className = 'insemail';
nextEmail.style.display = 'inline-block';
nextEmail.placeholder = 'Insira o Email';
inside_where = document.getElementById('addEmail');
inside_where.appendChild(nextEmail);
return false;
}
</script>
Assunto:<br><textarea rows="1" name="subject" cols="30"></textarea><br>
Mensagem:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input class="butao" type="submit" name="submit" value="Submit">
</form>
</div>
</div>
</body>
</html>
这是我创建的数据库的连接:
<?php
$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "escoladb";
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
if (mysqli_connect_errno())
{
echo "can't connect to MySQL: " . mysqli_connect_error();
}
?>
最后是联系方式,以便我可以发送电子邮件给我想要的学校:
<?php
if(isset($_POST['submit'])){
$to = implode(',', $_POST['email']);;
$from = "g.afonso.escola@gmail.com";
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "<div style=\"font-size:25px;background-color:white;text-align:center;\"> Email Enviado </div>";
}
?>