1

This is my code:

// $mail->addReplyTo('noreply@pbrx.co.id', 'No Reply');
$subjectTo = explode(';', $Addres);
//var_dump($Addres);
array($subjectTo);
// var_dump(array($subjectTo));
foreach ($subjectTo as $key => $value) {
    // $mail->isSMTP();     
    $mail->Protocol = 'smtp';
    $mail->Host = '192.168.40.220';
    $mail->Port = 25;
    $mail->SMTPDebug  = false;
    $mail->SMTPSecure = 'tls';
    $mail->SMTPAuth = true;
    $mail->From = 'noreply1@pbrx.co.id';
    $mail->FromName = 'Notes Email';
    $mail->addAddress($value);

    $subject = $supplier.' have sent NOTES FROM PO - '.$PO;
    if(substr($PO,-1)=='L'){
        $message = "Dear Purchasing,\nYou have NOTES from ".$supplier." with PO : ".$PO."\n Here the list :";               
    }else{
        $message = "Dear Merchandiser,\nYou have NOTES from ".$supplier." with PO : ".$PO."\n Here the list :";             
    }

    $nomor = 1;
    //var_dump($tbl_note->fetch_assoc());
    while ($val = $tbl_note->fetch_assoc()) {
        $message .= "\n".$nomor.". ITEM :".$val['itemdesc']." ( ".$val["matcontents"]." ) COLOR/SIZE :".$val['colorcode']."/".$val['size']." notes : ".$val['PIReason'];
        $nomor = $nomor + 1;
    }

    $mail->Subject = $subject;
    $mail->Body = $message ;
}

If I'm using just 1 address, the message show perfectly like these:

Dear Purchasing,
You have NOTES from COATS REJO INDONESIA with PO : NORT170283-014950-L
Here the list :
1. ITEM :EMB THREAD TEX 18 DRYVENT LOGO ( KXON ) COLOR/SIZE :ASPHALT GREY/SYLCO TEX 18 notes

But if I'm using multiple emails like these: usera@email.com;userb@email.com I get:

Dear Purchasing,
You have NOTES from COATS REJO INDONESIA with PO : NORT170283-014950-L
Here the list :

There's no item in there at same po. Did I do something wrong on looping the messages?

Thank you from mickmackusa, so i try this, i'm change position looping my list item before foreach, and make varibale in looping my list item. and last i'm using ny variable looping inside foreach. And working. Here the code i changed:

// $mail->addReplyTo('noreply@pbrx.co.id', 'No Reply');
    $subjectTo = explode(';', $Addres);
    //var_dump($Addres);
    array($subjectTo);
    // var_dump(array($subjectTo));             
        $nomor = 1;
        //var_dump($tbl_note->fetch_assoc());
        while ($val = $tbl_note->fetch_assoc()) {
            $listitem .= "\n".$nomor.". ITEM :".$val['itemdesc']." ( ".$val["matcontents"]." ) COLOR/SIZE :".$val['colorcode']."/".$val['size']." notes : ".$val['PIReason'];
            $nomor = $nomor + 1;
        }
    foreach ($subjectTo as $key => $value) {
        // $mail->isSMTP();     
        $mail->Protocol = 'smtp';
        $mail->Host = '192.168.40.220';
        $mail->Port = 25;
        $mail->SMTPDebug  = false;
        $mail->SMTPSecure = 'tls';
        $mail->SMTPAuth = true;
        $mail->From = 'noreply1@pbrx.co.id';
        $mail->FromName = 'Notes Email';
        $mail->addAddress($value);

        $subject = $supplier.' have sent NOTES FROM PO - '.$PO;
        if(substr($PO,-1)=='L'){
            $message = "Dear Purchasing,\nYou have NOTES from ".$supplier." with PO : ".$PO."\n Here the list :";               
        }else{
            $message = "Dear Merchandiser,\nYou have NOTES from ".$supplier." with PO : ".$PO."\n Here the list :";             
        }
        $message .= $listitem;

        $mail->Subject = $subject;
        $mail->Body = $message ;
    }
4

1 回答 1

1

mysqli_data_seek($tbl_note,0);当您进行多次迭代时,在您的 while 循环之前使用以重置指针。

更好的做法是从结果集中构建list消息部分,并将该文本设置为循环之外的变量(我不知道您的查询在哪里——它不在您的代码中),然后在循环中使用该变量连接消息。

于 2017-05-19T04:05:47.293 回答