1

我正在尝试发送批量邮件。它有效,但问题是当我检查这个显示的 Gmail 时。我可以使用密件抄送解决这个问题,但我想用于学习目的。

------------------------------------------
from:   example <example@gmail.com>
to: example1@gmail.com,
example2@gmail.com,
example2@gmail.com
date:   Dec 19, 2021, 1:18 AM
subject:    Testing Mail
mailed-by:  example
signed-by:  example
security:    Standard encryption (TLS) Learn more
---------------------------------------------

在收件人中,为什么所有订阅者的邮件都显示在“to”中。请帮我修复它。我想显示特定的订阅者邮件。

这是我的代码

<?php 
        if(isset($_POST['sendmail'])) {
            $status=1;
        $sql = "SELECT * FROM subscribers  WHERE status=? ORDER BY id ";
        $stmt = $conn2->prepare($sql); 
        $stmt->bind_param("s", $status);
        $stmt->execute();
        $result15 = $stmt->get_result();

            $mail = new PHPMailer;
            //$mail->SMTPDebug = 3;                               // Enable verbose debug output
            $mail->isSMTP();                                      // Set mailer to use SMTP
            $mail->Host = 'smtp.example.com';  // Specify main and backup SMTP servers
            $mail->SMTPAuth = true;                               // Enable SMTP authentication
            $mail->Username = EMAIL;                 // SMTP username
            $mail->Password = PASS;                           // SMTP password
            $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
            $mail->Port = 465;                                    // TCP port to connect to
            
            if (mysqli_num_rows($result15)>0) {
                while ($row = mysqli_fetch_array($result15)) {  
                    $mail->AddAddress($row['email']);  // Add a recipient 
                }
 }
                $mail->setFrom(EMAIL, 'example');
                //$mail->addReplyTo(NOREPLY);
                $mail->isHTML(true);                                  // Set email format to HTML

                $mail->Subject = $_POST['subject'];
                $mail->Body    = '<div style="border:2px solid red;">This is the HTML message body <b>in bold!</b></div>';
                $mail->AltBody = $_POST['message'];
                if (!$mail->send()) {
                    echo 'Message could not be sent.';
                    echo 'Mailer Error: ' . $mail->ErrorInfo;
                } else {
                    echo 'Message has been sent';
                }
                
}
     ?> 
4

0 回答 0