개발 Q&A

제목 메일이 보낼때 전에 있던 데이터가 자꾸 보내집니다.
카테고리 PHP
글쓴이 코the초보 작성시각 2020/05/25 19:10:12
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 7070   RSS

크론탭에 시간설정해서 한꺼번에 여러건의 메일를 보낼때 첨부파일에 처음에 보낼때 들어갔던 데이터들이 reset이 안되고 뒤에 붙어서 나옵니다.

public function SendEmail($param) {       

$this->load->helper('path');       

$this->load->library('email');

        $config['mailtype'] = 'html';       

$config['wordwrap'] = TRUE;     

  $this->email->initialize($config);

        $this->email->clear(TRUE);

        $this->email->from($this->config->item("mailtomail"), $this->config->item("mailtoname"));     

  $this->email->to($param['msgRcptAddress']);

        $this->email->subject($param['msgTitle']);             

  $inlineAttachment = array();     

  $attachmentList = array();   

    if ($param['msgAttachment'] != '') {     

      $msgAttachment = json_decode($param['msgAttachment']);         

  foreach ($msgAttachment as $attachment) {           

    if ($attachment->filetype == 'A') {               

    $filedata = array(                     

  'msgGroup' => $param['msgGroup'],                        

                  'msgNo' => $param['msgNo'],                                  

  );               

    $attachment->file = $this->getMailingAttachmentTypeA($filedata);                 

  $this->email->message($param['msgContent']);           

    } else if ($attachment->filetype == 'C') {               

    $filedata = array(                       

     'msgGroup' => $param['msgGroup'],   

      'msgNo' => $param['msgNo'],                   

         );       

            $attachment->file = $this->getMailingAttachmentTypeC($filedata);       

            $inlineAttachment = array_pop($attachment->file);

          $this->email->message($param['msgContent'].$inlineAttachment);     

                                }                             

  if ($attachment->file && !empty($attachment->file)) {     

              if (is_string($attachment->file)) {                       

                       $attachment->file = array($attachment->file);

                    }                                   

    if (in_array($attachment->filetype, array('1','2','3'))) {     

                  $attachmentPath .= "{$param['msgNo']}/";           

        }                 

        foreach ($attachment->file as $file) {     

                  $attachmentList[] = $attachmentPath . "{$file}";       

            }                                 

  }         

  }   

    }     

  foreach ($attachmentList as $file) {         

  $this->email->attach($file);     

  }

        if (! $this->email->send()) {     

      $msgStatus = '3';     

  } else {         

  $msgStatus = '2';       

}           

  $data = array('msgStatus'=>$msgStatus);     

  $where = array('msgNo'=> $param['msgNo']);     

  $this->Update($data, $where);     

  

    return;    }

 

 

 

public function getMailingAttachmentTypeC($data) {       

$this->load->helper('file');     

     

$this->load->library("phpexcel");             

  $data['today'] = date('Y-m-d');       

...

$cNo = $data["cNo"];               

$company = $this->CompanyModel->SelectRow($cpNo);       

     

 

$ldParams["cNo"] = $cNo;                

  $course = $this->CourseModel->SelectRow($cNo);       

      

        ini_set('memory_limit', '5000M');             

  $type = $data["type"];               

 

    $params["cNo"] = $cNo;     

      $params["oType"] = "ASC";               

 

  $studentList = array();   

    $studentList = $this->StudyModel->StudentSelectList($params); 

      $course = $this->CourseModel->SelectRow($studentList[0]['csNo']); 

              // 엑셀파일의  내용을 메일의 본문에서도 볼 수 있게 HTML 파일도 함께 생성   

    $excelhtml = array();       

$studentList["list"] = $studentList;   

 

   .....

      

    $i=6; 

      $j=1; 

      $colsize = 8;       

         if(is_array($studentList)) {                       

foreach ($studentList["list"] as $st_row) {                                // Add some data       

           

      $cNo = $this->config->item("docPreffix") . sprintf("%'03d", $st_row["cNo"]);       

                             

  $stTotalTIme = round($st_row["stTotalTime"]/60);                                // 분단위 시간을 알맞게 글자로 변환           

    $timeStr = '';       

        if ($stTotalTIme < 60) { 

                  $timeStr = $stTotalTIme.'분'; 

              } else if ($stTotalTIme >= 60 && $stTotalTIme < 1440) {       

            $h = floor($stTotalTIme / 60);                   

$m = $stTotalTIme - (60 * $h);                   

$timeStr = $h.'시간';                 

         

  if ($h > 0) $timeStr .= ' '.$h.'시간';       

            if ($m > 0) $timeStr .= ' '.$m.'분';               

}           

    //->setCellValue("D".$i, number_format($stTotalTIme)."분")           

    $this->phpexcel ->setActiveSheetIndex(0)               

 

 

        ->setCellValue("C".$i, $st_row["cTitle"])             

  ->setCellValue("D".$i, $timeStr)           

    ->setCellValue("E".$i, $st_row["stProgress"]."%")     

         

                      if ($type === "safety" && $stTotalTIme < 120 ) {             

      $this->phpexcel->setActiveSheetIndex(0)->getStyle("D".$i)     

                      }             

               

        }                           

    $excelhtmldata = array(       

            'col' => array( $st_row["stProgress"]."%", $exam."/".$task),                    'style' => array('', '', '', '', ''),                );                       

        if ($course["csMinRate"] > 0) {               

    if ($st_row["stProgress"] < 20) {                     

  $excelhtmldata['style'][3]  = 'red';                 

  } elseif ($st_row["stProgress"] < $course["csMinRate"]) {           

            $excelhtmldata['style'][3]  = 'yellow';         

          }                }                           

                   

  $excelhtml[] = $excelhtmldata;                         

      $j++;     

          $i++;                             

  if($j > $colsize){             

      $j = 1;               

}             

          } // foreach                 

                    $this->phpexcel->getActiveSheet()->setTitle($title);            

$this->phpexcel->setActiveSheetIndex(0);             

         $filepath = FCPATH . "data/$data['msgNo']}/";       

if (!file_exists($filepath)) {       

    mkdir($filepath, 0777, true);        }   

      $filename = "report_list_{$data['msgNo']}.xls"; 

  $filename = $this->set_filename($filepath, $filename);     

  $objWriter = PHPExcel_IOFactory::createWriter($this->phpexcel, 'Excel5');       

$objWriter->save($filepath.$filename);             

  $htmldata = "<table width='640' cellspacing='0' cellpadding='4' style='border-collapse:collapse;font-size:10pt;width:640px;'>";        $htmldata.= "<thead><tr style='background:#eee;'><th style='border:1px solid #ccc'>성명</th><th style='border:1px solid #ccc'>아이디</th></tr></thead>";     

  $htmldata.= "<tbody>";   

    foreach ($excelhtml as $row) {         

  $tr = "<tr>";     

      $tr.= "<td style='border:1px solid #ccc;'>{$row['col'][0]}</td>"; 

          $tr.= "<td style='border:1px solid #ccc;'>{$row['col'][1]}</td>";   

          $tr.= "</tr>";         

  $htmldata .= $tr;   

    }   

    $htmldata.= "</tbody>";   

    $htmldata .= "</table>";     

          return array($filename, $htmldata);   

}

 

report_list.xsl를 만들때 데이터가  꼬입니다.

debug찍어보면 로그상에는 정상적으로 찍히는데 실제 첨부된 파일에 보면 전에있던 파일 내용이 엎어써지거나 다른 리스트가 덧붙여서 나오고 있어요.

어디서 초기화를 해야할지 아니면 메일 하나 보내고 시간텀을 줘야하는건지 도통 모르겠습니다.

$studentList = array();초기화 해봤는데 같은 현상이 일어납니다.

며칠째 같은 현상인데 도저히 해결이 안되서 이렇게 장문의 소스와 함께 글 올립니다.

도와주세요~~~~ㅜ,ㅠ

 다음글 갑자기 mssql_query() 함수가 오류 나고 아파... (2)
 이전글 ajax를 이용하여 파일 업로드 시 403에러 문제 (3)

댓글

엽토군 / 2020/05/27 07:33:19 / 추천 0
코드 블록좀 써주세요 ㅠㅠ 루프를 어떻게 돌고 있는지가 안보이네요.
변종원(웅파) / 2020/05/27 10:01:58 / 추천 0
소스 보기가 힘드네요. 잠깐 봤는데 $attachment->file  여기에 배열로 담기고 있는데 확인해보세요.