【发布时间】:2020-07-28 23:42:23
【问题描述】:
[![工作但显示每封邮件的所有电子邮件][1]][1]我有一个 php 脚本,当用户回复帖子时应该向管理员发送电子邮件。这工作正常,但它同时发送 4 封邮件,并且针对同一记录发送同一封邮件,而不是发送 1 封邮件 使用phpmailer发送邮件
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'noreply@joint2purchase.com';
$mail->Password = 'manjunath123M';
$mail->setFrom('noreply@joint2purchase.com', 'admin joint2purchase');
$stmt = $db->query('SELECT USERNAME,EMAIL FROM MEMBERS LIMIT 100');
//for each email add a recipient
while($row3 = $stmt->fetch()){
$toname = $row3['USERNAME'];
$tomail = $row3['EMAIL'];
$mail->addAddress($tomail);
}
//build the rest email (html, attaches, etc)
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'created new thread';
$mail->Body = '<html>
<head>
<title>Admin Started with You : '.$name.' </title>
</head>
<body>
<h1>Thanks you for joining with us!</h1>
<table cellspacing="0" style="border: 2px solid #202020; height: 60%; width: 100%;">
<tr style="background-color:lightblue;">
<th>Joint2Purchase</th>
</tr>
<br/> <br/>
<tr style="background-color: white;">
<th>'.$toname.', started a new conversation with you at Joint2Purcahse. </th>
</tr>
<tr>
<th style="color:skyblue; font-size:30px; font-family:calibri; font-weight:boldder; border-bottom:1px solid skyblue;"> '.$name.'</th>
</tr>
<tr style="height:70px;">
<br/> <a href="joint2purchase.com/viewthread.php?id='.$example.'">View Conversation</a></th>
</tr>
</table>
</body>
</html>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->addAttachment('test.txt');
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'The email message was sent.';
}```
[![enter image description here][2]][2]
[1]: https://i.stack.imgur.com/q5K06.png
[2]: https://i.stack.imgur.com/hIJdZ.png
【问题讨论】: