How to send multiple attachments in mail at the time of generating pdf in codeigniter |
-
ArshKhan
Newbie
-
Posts: 1
Threads: 1
Joined: Aug 2018
Reputation:
0
Code: public function multisalarySlippdf_mail(){
$file = 'Salary Slip';
$pdfFilePath1 = FCPATH . "uploads/".$file.".pdf";
if(file_exists($pdfFilePath1)){
unlink($pdfFilePath1);
}
$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
if(!empty($emailid)){
$html = $this->load->view('admin/salarySlippdf',
['salaries'=>$sal,
'workingDays'=>$working_days,
'present'=>$present,
'absent'=>$absent,'extraday'=>$extraday,],true);
}
$this->m_pdf->pdf->WriteHTML($html);
$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->clear(TRUE);
$this->email->set_newline("\r\n");
$this->email->from('[email protected]');
$this->email->to($emailid);
$this->email->subject($subject);
$this->email->message($message);
$this->email->attach($pdfFilePath1);
if($this->email->send()){
echo "send";
}
else{
show_error($this->email->print_debugger());
}unlink($pdfFilePath1);
}
}
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.
|
Messages In This Thread |
How to send multiple attachments in mail at the time of generating pdf in codeigniter - by ArshKhan - 08-28-2018, 10:51 PM
|