lundi 1 janvier 2018

Passing data from one view to email template view on checkbox checked in code-igniter

I'm using a code-igniter to develop an web application. I'm trying to create a dynamic email template which loads data dynamically when I'm check a checkbox from other view.

Here is my scenario: enter image description here

If I'm checking a checkbox for HMO_001, then all data that will loaded in the table for HMO_001 will pass to my email template, and when I'm click on Send button the mail will send to particular landlord.

Now I'm able to send an email to multiple landlords at a time on button click when I'm check multiple checkbox, but the email is hard coded. I'm trying to make it dynamic, but no success.

Here is my Code:

Controller to load table data:

public function index()
    {
        # code...
        $user = $this->ion_auth->user()->row();
        $data['username'] = $user->username;
        $data['user_id'] = $user->id;

        $landlord = $this->input->post('landlord_id');
        $property = $this->input->post('property_id');
        $certificate = $this->input->post('certificate_id');

        if( $landlord =='') {
            $landlord = 0;
        }
        if($property == ''){
            $property = 0;
        }
        if($certificate == ''){
            $certificate = 0;
        }

        $data['landlords'] = $this->c->landlordList();
        //$data['properties'] = $this->c->propertyList();
        $data['certificates'] = $this->c->certificateList();
        //$data['certified'] = $this->c->certificate_List();

        $data['certified'] = $this->c->getcertificateByLandlordProperty($landlord, $property, $certificate);

        // print_r($data['landlords']);
        // print_r($data['properties']);
        // echo "<pre>";
        // print_r($data['certificates']);
        // echo "</pre>";
        // exit();
        $data['title'] = 'Certificate List';

        $this->load->view('template/header', $data);
        $this->load->view('certificate/certificate_list', $data);
        $this->load->view('template/footer');
    }

Controller to send mail:

public function sendMail()
    {
        # code...
        //$data['certified'] = $this->c->getcertificateByLandlordProperty($landlord, $property, $certificate);


        if(isset($_POST['submit'])){//to run PHP script on submit
            if(!empty($_POST['sendMail'])){
            // Loop to store and display values of individual checked checkbox.
                foreach($_POST['sendMail'] as $selected){
                    //echo $selected."</br>";
                }
            }
        }

        $email_to = $this->input->post('sendMail[]');

        <!-- echo "<pre>";
        print_r($email_to);
        echo "</pre>";
        exit(); -->
        $body = $this->load->view('emailTemplate/certTemplate', $data);

        $this->load->library('email');        
        $config = array();
            $config['protocol'] = 'mail';
            $config['smtp_port'] = 587;
            $config['smtp_host'] = 'smtp.office365.com';
            $config['smtp_user'] = 'info@admin.com';
            $config['smtp_pass'] = '**********';
            $config['smtp_crypto'] = 'STARTTLS';   
            $config['newline'] = "\r\n"; //REQUIRED! Notice the double quotes!
            $config['crlf'] = "\r\n";
            $config['mailtype'] = "html";

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

        $this->email->from('info@admin.com', 'Administrator');
        $this->email->to($email_to);
        $this->email->subject('Your Subject');
        $this->email->message('$body');

        $sent = $this->email->send();

        if ($sent)
        {
            echo 'OK, mail send successfully';

        } else {
            echo $this->email->print_debugger();
        }
    }

Any kind of help is welcome, Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire