我想将相同的电子邮件发送给多个收件人,我的代码如下:
我的contact.php所以我可以编辑我想要的信息和主题在我的网站
<?php
if(isset($_POST['submit'])){
$to = $_POST['email'];
$from = "my_email@gmail.com";
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Email enviado";
}
?>
我的index.php,dbh.php是与数据库的连接。
<?php
include_once 'dbh.php';
include_once 'contact.php';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<style>
body {
background-image: url("http://mapinstitute.org/data/wallpapers/110/im58522201.jpg");
}
.mail {
width:355px;
height:550px;
font-size:25px;
text-align:center;
color:white;
}
</style>
</head>
<body>
<div class="container-fluid">
<?php
$sql = "SELECT Nome,EmailGeral FROM escolas;";
$result = mysqli_query($conn, $sql);
echo "<select name='Nome' multiple='multiple'>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='" . $row['Nome'] ."'>" . $row['Nome'] ."</option>";
"<option value='" . $row['EmailGeral'] ."'>" . $row['EmailGeral'] ."</option>";
}
echo "</select>";
?>
<div class="row justify-content-center">
<div class="mail">
<form action="" method="post">
<button type="button" onclick="emailNext();">Add 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 = 'class_for_styling';
nextEmail.style.display = 'block';
nextEmail.placeholder = 'Insert your Email';
inside_where = document.getElementById('addEmail');
inside_where.appendChild(nextEmail);
return false;
}
</script>
Subject:<br><textarea rows="1" name="subject" cols="30"></textarea><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
</form>
</div>
</div>
</div>
</body>
</html>
当我执行我的代码时,它只发送到最后提交的电子邮件。我做错了什么?
答案 0 :(得分:0)
尝试:
nextEmail.name = 'email[]';
使用:
$to = implode(',', $_POST['email']);