亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

phpmail 發送 4 封郵件而不是 1 封

phpmail 發送 4 封郵件而不是 1 封

PHP
慕桂英4014372 2022-12-23 16:37:53
    我有一個 php 腳本,當用戶回復帖子時應該向管理員發送一封電子郵件。這工作正常,但它同時發送 4 封郵件,并且對于相同記錄的相同郵件,而不是使用 phpmailer 發送郵件來發送 1 封郵件    $mail = new PHPMailer;    $mail->isSMTP();    $mail->SMTPDebug = 2;    $mail->Host = 'smtp.hostinger.com';    $mail->Port = 587;    $mail->SMTPAuth = true;    $mail->Username = '[email protected]';    $mail->Password = 'manjunath123M';    $mail->setFrom('[email protected]', '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>';  
查看完整描述

3 回答

?
陪伴而非守候

TA貢獻1757條經驗 獲得超8個贊

1st)你執行一個查詢(最后一個),你將“EMAIL”字段放入 $to 中,之后你不在你的郵件結構中使用它!所以一個無用的查詢

2nd)你有一個循環內的郵件代碼

while($row3 = $stmt->fetch()){

對于您獲得的每條記錄。因此,如果最后一個查詢返回 3 或 4 或 100 條記錄,您發送的電子郵件數量相同??!


查看完整回答
反對 回復 2022-12-23
?
繁花如伊

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 = '[email protected]';

    $mail->Password = 'filip321';

    $mail->setFrom('[email protected]', '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.';

    }


查看完整回答
反對 回復 2022-12-23
?
手掌心

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 = '[email protected]';

$mail->Password = 'filip321';

$mail->setFrom('[email protected]', 'Client Filip');

//comment this line/ $mail->addReplyTo('[email protected]', 'Client Filip');

$mail->addAddress('[email protected]', '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/ }

你只發送一封電子郵件


查看完整回答
反對 回復 2022-12-23
  • 3 回答
  • 0 關注
  • 155 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號