gpt4 book ai didi

PhpMailer、ClearAddresses() 不起作用,消息发送给所有人

转载 作者:行者123 更新时间:2023-12-04 00:11:47 25 4
gpt4 key购买 nike

我正在尝试向不同的用户发送不同的消息。我创建了一个电子邮件地址数组,在遍历它时,我想将 message2 发送给 user2。

在重复使用相同的邮件实例时,在每次迭代开始时我声明.

我错过了什么地址不会在迭代开始时被清除?

谢谢!

// settings

$mail = new PHPMailer;

$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'xxx'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxx'; // SMTP username
$mail->Password = 'xxx'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;
$mail->CharSet = "UTF-8"; // TCP port to connect to

function sendInvoice($mail, $addresses) {
foreach($addresses as $recipient) {
$mail->ClearAddresses();
$mail->setFrom('mail@domain.eu', 'My Server');
$mail->addAddress($recipient['email'], $recipient['name']); // Add a recipient
$mail->addReplyTo('mail@domain.eu', 'My Server');
$mail->isHTML(true);
$mail->Subject = $recipient[subject];
//$mail->Body = $message;
$mail->MsgHTML($recipient[message]);

if (! $mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
//echo 'Message has been sent';
}
}
}

最佳答案

在您的代码中,更改:

$mail->ClearAddresses();

到:

$mail->ClearAllRecipients();

这应该可以解决问题。

关于PhpMailer、ClearAddresses() 不起作用,消息发送给所有人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33629707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com