M
M
mars1302021-06-29 16:12:46
PHP
mars130, 2021-06-29 16:12:46

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>';
}
?>


The task is to find out information about a person in a cycle. Echo made to check, but I see a blank screen.

$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

1 answer(s)
F
FanatPHP, 2021-06-29
@FanatPHP

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);

the $data array will contain a list of users

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question