CodeIgniter Laravel PHP Example Javascript jQuery MORE Videos New

How to send Email with multiple attachment Codeigniter


Contrroller

    <?php
defined('BASEPATH') OR exit('No direct script access allowed');

/*require_once('vendor/tcpdf/examples/tcpdf_include.php');*/
class Quotation extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        if ($this->session->userdata('logged_in') != 1){
            redirect('home');
        } 
        $this->load->model('quotationmodel');
        $this->load->library('form_validation');
        
    }
    public function sendmail(){
        $attachmentdata = $this->quotationmodel->AttachmentDetailsByID($attachment_id);
        $is_mail=true;
        if($is_mail){
        $config = Array(
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.gmail.com',
            'smtp_port' => 465,
            'smtp_user' => 'divyasundarsahu@gmail.com',
            'smtp_pass' => 'tvrofmzfixhpynbq',
            'mailtype'  => 'html', 
            'charset'   => 'iso-8859-1'
        );
        $this->load->library('email', $config);
        $this->email->set_newline("\r\n");
        $this->email->from('divyasundarsahu@gmail.com', 'TNT');
        $this->email->to(implode(', ', $to).','.$client_mail->UserEmail);
        $this->email->subject($name_data['name']);
        /*$this->email->isHTML(true); */
        /*Quotation*/
        $this->email->attach("uploads/quotation/$FileNumber-$SlNo.pdf");

        foreach($attachmentdata as $attach)
        {
            
            $this->email->attach("uploads/attachment/$attach->Document");
        }
        
        
        $email_content=$name_data['email_content'];
        $email_footer=$email_signature;
        $message = "$email_content
        $email_footer
        " ;
        $this->email->message($message);
        if ( ! $this->email->send()) {
            show_error($this->email->print_debugger());
        }
    }
}
?>

Model

    <?php
defined('BASEPATH') or exit('No direct script access allowed');
date_default_timezone_set("Asia/Calcutta");
class Quotationmodel extends CI_Model
{
    
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
    public function AttachmentDetailsByID($attachment_id){
        $query = $this->db->select("AutoID,Document");
        $this->db->from('attachquotation');
        $this->db->where_in('AutoID',$attachment_id);
        $query = $this->db->get();
        return $query->result();
    }
}