3 回答
TA贡献1757条经验 获得超8个赞
1st)你执行一个查询(最后一个),你将“EMAIL”字段放入 $to 中,之后你不在你的邮件结构中使用它!所以一个无用的查询
2nd)你有一个循环内的邮件代码
while($row3 = $stmt->fetch()){
对于您获得的每条记录。因此,如果最后一个查询返回 3 或 4 或 100 条记录,您发送的电子邮件数量相同!!
TA贡献2012条经验 获得超12个赞
这会将同一封电子邮件发送给许多收件人
//Set the mailer hadle
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'filip@joint2purchase.com';
$mail->Password = 'filip321';
$mail->setFrom('filip@joint2purchase.com', 'Client Filip');
//get the administrators emails
$stmt = $db->prepare('SELECT USERNAME,EMAIL,TYPE FROM MEMBERS WHERE TYPE = :T LIMIT 100');
$stmt->execute(array(':T' => 'ADMINISTRATOR'));
//for each email add a recipient
while($row3 = $stmt->fetch()){
$toname = $row3['USERNAME'];
$tomail = $row3['EMAIL'];
//*************************************************
//So you have to use bcc (blind carbon copy)
//COMMENT THE NEXT LINE
//$mail->addAddress($tomail, $toname);
//ADD THIS LINE
$mail->AddBCC($tomail, $toname);
//*************************************************
}
//build the rest email (html, attaches, etc)
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$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.';
}
TA贡献1942条经验 获得超3个赞
像那样:
//comment this line/ $stmt = $db->prepare('SELECT USERNAME,EMAIL,TYPE FROM MEMBERS WHERE TYPE = :T LIMIT 100');
//comment this line/ $stmt->execute(array(':T' => 'ADMINISTRATOR'));
//comment this line/ while($row3 = $stmt->fetch()){
$to = $row3['EMAIL'];
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'filip@joint2purchase.com';
$mail->Password = 'filip321';
$mail->setFrom('filip@joint2purchase.com', 'Client Filip');
//comment this line/ $mail->addReplyTo('manubmhegde@gmail.com', 'Client Filip');
$mail->addAddress('manubmhegde@gmail.com', 'Receiver Name');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$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.';
}
//comment this line/ }
你只发送一封电子邮件
- 3 回答
- 0 关注
- 120 浏览
添加回答
举报