使用 SMTP PHPMailer 向不同的电子邮件帐户发送不同的消息

send different messages to different email accounts using SMTP PHPMailer

我想向从我的数据库中获取的不同电子邮件帐户发送不同的邮件, 电子邮件最多可以是从数据库中提取的 100 封电子邮件,并且每个电子邮件帐户的消息必须不同, 我试过这个代码但不幸的是它只向第一个用户发送一条消息。 我在这段代码中有什么错误,请帮助我,谢谢。

<?php
  use PHPMailer\PHPMailer\PHPMailer; 
  use PHPMailer\PHPMailer\Exception;  
  require 'class/src/Exception.php'; 
  require 'class/src/PHPMailer.php'; 
  require 'class/src/SMTP.php'; 
            $mail = new PHPMailer();
            $mail->isSMTP();
            $mail->Host     = 'mail.company.com';
            $mail->SMTPAuth = true;
            $mail->Username = 'help@company.com';
            $mail->Password = '****************';
            $mail->SMTPSecure = 'ssl';
            $mail->Port     = 465;
            $mail->SMTPKeepAlive = true;
            $mail->setFrom('help@company.com', 'CompanyName');
            $mail->Subject = "Common Header of all of the Emails";
   $fetch_data = $conn->query("SELECT name, email FROM db_table WHERE status = 'Active'");
   foreach ($fetch_data as $fetched_data) {
   $name = $fetched_data['name'];
   $email = $fetched_data['email'];
  //========================= SEND IN FOREACH LOOP =========================>
            $mail->isHTML(true);
            $mail->CharSet = 'UTF-8';
            $mail->addAddress($email, $name);
            $mail->Body = " <h3>Hi $name,</h3><h4>Congrats!</h4>";
            $mail->send();
            $mail->ClearAllRecipients();  //  $mail->clearAddresses(); NOT WORKING
}
  ?>

调试建议。

<?php

$fetch_data = $conn->query("SELECT name, email FROM db_table WHERE status = 'Active'");
print_r($fetch_data); // Do you have all row you need
   foreach ($fetch_data as $fetched_data) {
   print_r($fetched_data); // Do you have all row you need
   $name = $fetched_data['name'];
   $email = $fetched_data['email'];
  //========================= SEND IN FOREACH LOOP =========================>
            $mail->isHTML(true);
            $mail->CharSet = 'UTF-8';
            $mail->addAddress($email, $name);
            $mail->Body = " <h3>Hi $name,</h3><h4>Congrats!</h4>";
            $mail->send();
            $mail->ClearAllRecipients();  //  $mail->clearAddresses(); NOT WORKING
}