I'm trying to send multiple separate emails to multiple addresses. The below code sends it in 1 email with multiple TO addresses. This becomes an issue because everyone in the email can see each other's email addresses.
Is there a way to send separate emails?
<?php
$smtp = 'xxx.com';
$port = 25;
$secure = 'tls';
$username = 'test@xxx.com';
$pass = '';
$from = 'test@xxx.com';
$to = 'info@xxx.com';
$to1 = '';
$subject = 'Test Email';
$content = $mail_content;
require_once("include/class.phpmailer.php");
$mail=new PHPMailer(true);
$mail->IsSMTP();
try{
$mail->Host = $smtp;
$mail->SMTPAuth = true;
$mail->Port = $port;
$mail->SMTPSecure = $secure;
$mail->Username = $username;
$mail->Password = $pass;
$mail->SetFrom($from);
if (isset($email) && $email) {
$mail->AddAddress($email);
}
else {
while($row = mysqli_fetch_object($result)) {
$mail->AddAddress($row->email);
echo $row->email."<br>";
}
}
$mail->Subject = $subject;
$mail->MsgHTML($content);
$mail->Send();
if (isset($email) && $email) {
?>
<script>location.href="<?php echo '../index.php' . $_REQUEST['redirect']; ?>";</script>
<?php
}
}
catch (phpmailerException $e){
echo $e->errorMessage();
}
catch (Exception $e){
echo $e->getMessage();
}
?>