我正在尝试使用phpmailer将电子邮件发送到数据库中找到的每个电子邮件地址,但作为唯一的电子邮件。由于某种原因,它发送重复的电子邮件,并以与我的查询返回行一样多的副本发送出去。因此,如果我的查询返回5行,则每个收件人将收到5封电子邮件(发送的电子邮件总数为25)。由于电子邮件内容是个性化的,因此我无法将同一封电子邮件用于多个收件人。

我的代码在做什么错?请帮忙...

这是我的代码:

$customers_query = "SELECT customer_name, customer_email, customer_id FROM customers";

    $customers = mysql_query($customers_query);

    if (!$customers) {
        $message  = 'Error notice: ' . mysql_error() . "\n";
        $message .= 'Whole query: ' . $query;
    die($message);
    }

    require_once('class.phpmailer.php');
    // create an instance

    while ($row = mysql_fetch_array($customers)) {
        $email = $row['customer_email'];
        $name = $row['customers_name'];
        $id = $row['customer_id'];
        $mail = new PHPMailer();
        // use sendmail for the mailer
        $mail->IsSendmail();
        $mail->SingleTo = true;
        $mail->IsHTML(true);
        $mail->From = "noreply@domain.com";
        $mail->FromName = "MyWebsite";
        $mail->Subject = "Welcome to MyWebsite";
        $mail->AddAddress($email);

        $mail->Body = "Dear ".$name.", welcome to MyWebsite. Your ID is: ".$id.". Enjoy your stay.";
        $mail->Send();
    }


那么,这里缺少什么?为什么会发送那么多电子邮件?

最佳答案

尝试这个:

$mail->ClearAddresses(); after $mail->Send();

关于php - phpmailer与mysql结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22106774/

10-10 18:20
查看更多