Answer the question
In order to leave comments, you need to log in
How to form an array through Multiply select to send individual emails?
Greetings. Please tell me how to solve the technical problem.
There is Select in which you can select multiple email addresses to form recipients.
<select name="recipient[]" class="select2 form-control select2-multiple" multiple="multiple" multiple data-placeholder="Choose ...">
<?php
$sql = mysql_query("SELECT * FROM `users` ");
while ($result = mysql_fetch_array($sql))
{
echo
'<option value="'.$result['email'].'">'.$result['email'].'</option>';
}
?>
$subject = trim($_POST['subject']);
$users_group_list = $_POST['recipient'];
$text_email=trim($_POST['text_email']);
$users_info = mysql_query("SELECT * FROM `users` WHERE email='".$users_group_list."'");
while ($result_user_info = mysql_fetch_array($users_info))
{
echo $result_user_info['name'];
echo $result_group_info;
echo $subject;
echo $message;
}
Answer the question
In order to leave comments, you need to log in
Learning how to work with the database.
1. throw mysql_query in the trash, this code will not work on any normal hosting
2. rewrite the code like this
$in = str_repeat('?,', count($users_group_list) - 1) . '?';
$sql = "SELECT * FROM `users` WHERE email IN ($in)";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param(str_repeat('s', count($array)), ...$users_group_list);
$Stmt->execute();
$result = $stmt->get_result();
$data = $result->fetch_all(MYSQLI_ASSOC);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question