My question is that I need to get a data (email) from different tables with one query. I have searched and I couldnt find enough information so I decided to ask here.
The idea is to send email to certain people from different departments and also send the email to everybody in all departments. My code is below;
if ($_POST['recipient'] == 'parents'){$query = "SELECT `email`, `first_name` FROM `users` WHERE `allow_email` = 1 AND `active` = 1";}
        if ($_POST['recipient'] == 'teachers'){$query = "SELECT `email`, `name` FROM `teachers` WHERE `status` = 1";}
        if ($_POST['recipient'] == 'staff'){$query = "SELECT `email`, `name` FROM `staff`";}
        $result = $con->query($query);
        while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
            $mail = new PHPMailer();
            $mail->IsHTML(true);
            $mail->SMTPAuth   = true;                  // enable SMTP authentication
            $mail->Host       = $site_settings['smtp_host']; // sets the SMTP server
            $mail->Port       = 26;                    // set the SMTP port
            $mail->Username   = $site_settings['smtp_username']; // SMTP account username
            $mail->Password   = $site_settings['smtp_password']; // SMTP account password
            $email->From      = $site_settings['school_email'];
            $email->FromName  = $site_settings['school_name'];
            $email->Subject   = 'Newsletter: '.$_POST['subject'];
            $email->Body      = $_POST['body'];
            $email->AddAddress( $row['email'] );
            $email->Send(); 
        }
Could anyone help?
 
     
     
    