Mailer = "smt-6ren">
gpt4 book ai didi

PHPMailer 发送重复的电子邮件

转载 作者:可可西里 更新时间:2023-11-01 01:00:54 25 4
gpt4 key购买 nike

PHPMailer

<?php
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->SMTPSecure = "tls";
$mail->Mailer = "smtp";
$mail->Host = "smtp.office365.com";
$mail->Port = 587;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "xxx";
$mail->Password = "xxx";
$mail->setFrom('xxx', 'Website');

//Send to Admin
$AdminEmail = 'admin.example@gmail.com';
$mail->AddAddress($AdminEmail, $AdminName);
$mail->Subject = "This is an email";
$mail2 = clone $mail;
$body = 'Hi Admin. This is an email';
$mail->Body = $body;

if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}

//Send to User
$UserEmail = 'user.example@gmail.com';
$mail2->AddAddress($UserEmail, $UserName);
$body2 = 'Hi User. This is an email';
$mail2->Body = $body2;

if(!$mail2->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail2->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>

我有一个问题,当我发送电子邮件时,Admin 将收到 $mail$mail2,而他们应该只收到 $邮件。虽然 User 没有问题。通过接收 $mail2 正常工作。我试过放置 $mail->ClearAddresses(); 但它仍然是一样的。碰巧有什么问题?

最佳答案

在添加管理员的地址和内容之前克隆电子邮件变量。 (如评论中所建议)

关于PHPMailer 发送重复的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27185452/

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