2017-03-11 8 views
1

私は次のコードを持っています。$ byCreatedBy配列をループし、 $ createdByごとにxlsファイルを作成し、 $ createdByごとにxlsファイルを添付します。 しかし、以前のメッセージの添付ファイル/ sの次のメッセージが生じ$アタッチメント配列を再初期化しないYii2 mailer compose()ループで使用されている添付ファイルをリセットしない

$mail = \Yii::$app->mail->compose(); 

ようです。私はzyxphpmailerプラグイン

を使用していますので、

 $mail->adapter->clearAttachments(); 

は、添付ファイルをクリアします:

 $mail = \Yii::$app->mail; 
     $mail->adapter->clearAttachments(); 
     $message = $mail->compose(); 
     $message->setTo([ 
      '[email protected]' => 'Milwell', 
     ]) 
     ->setSubject('Pending Internal Requistions') 
     ->setHtmlBody(Yii::$app->view->render('/mail/pending-requisitions',[ 
      'username'=>$createdBy, 
      'email'=>$emailAddress, 
     ])); 
     $message->attach($filename); 
     $message->send(); 

ライン:

 foreach($byCreatedBy as $createdBy=>$data){ 
     $filename = \Yii::$app->params['data_dir']."pending-requisitions/pendingIR-".$createdBy.".xls"; 
     $this->xls = new MilPHPExcel; 
     $this->writeRequisitions($data); 
     $this->xls->outputFile($filename); 
     $emailAddress = PeopleData::getEmailAddressByUsername($createdBy); 

     $mail = \Yii::$app->mail->compose(); 
     $mail->setTo([ 
      '[email protected]' => 'Milwell', 
     ]) 
     ->setSubject('Pending Internal Requistions') 
     ->setHtmlBody(Yii::$app->view->render('/mail/pending-requisitions',[ 
      'username'=>$createdBy, 
      'email'=>$emailAddress, 
     ])) 
     ->attach($filename) 
     ->send(); 
     if($i>1) 
      exit(); 
     $i++; 
    } 

答えて

1

は、にメールコードを変更しました
関連する問題