Welcome Guest, Not a member yet? Register   Sign In
How to send multiple attachments in mail at the time of generating pdf in codeigniter

public function multisalarySlippdf_mail(){

$file = 'Salary Slip';
$pdfFilePath1 = FCPATH . "uploads/".$file.".pdf";
$this->load->library('m_pdf');// load mpdf library
$config = Array(
       'protocol' => 'smtp',
       'smtp_host' => 'ssl://smtp.googlemail.com',
       'smtp_port' => 465,
       'smtp_user' => '[email protected]',
       'smtp_pass' => 'pccpl525',
       'charset' => 'iso-8859-1',
       'mailtype' => 'html',
       'charset' => 'utf-8',
       'newline' => '\r\n',
       'crlf'  => '\n',
       'wordwrap' => TRUE

$salaries  = $this->report->fetchAlldata();// fetching salary data from
                                          database using report model

foreach($salarie as $sal){
$emailid = $sal->official_email; // fetch email ids from the database
$html = $this->load->view('admin/salarySlippdf',
$this->m_pdf->pdf->Output($pdfFilePath1, "F");// saved file in given path
$subject = " Salary Slip";
$message = "Please Download file".' '.$emailid;
$this->load->library('email', $config);
$this->email->from('[email protected]');
  echo "send";
return redirect('admin/report/salaryslipmail');

My code is sending mail perfectly but there is problem in attachment. In mail attachment one employee received his salary slip but second employees also received the first employee attachment(same) two times in one mail and third employee also received the same attachment three times. I don't know where is the problem in my code. I have little bit knowledge of Php. Please guide me. Thanks in advance.

It's probably when you were doing debug.

$this->email->print_debugger() only works if you don't clear email after send with $this->email->send(false). The problem with that is, it'll keep all attachments in place too.

If you uncomment $this->email->clear(TRUE) - that will clear all the previous email data, and with true attribute, it will also clear attachments.

Theme © iAndrew 2016 - Forum software by © MyBB