Sending Email to multiple addresses from multiselect option using codeigniter-PHP

I have a multiselect dropdown, which allows me to select more than one user at a time. I want to be able to select more than one user and when I click on the “Send code” button, the application will snow send email to these users using the email addresses. Currently when I select and click “Send Code”, the application will only send email to only one user leaving other once. Please I will like to know to be sending email to all selected users at a time. I’m using CodeIgniter and below is my code:

Below is the view section of my code, which enable user to select users and send code:

     <meta charset="UTF-8">
     <title>Member Invite</title>
    <form class="form-horizontal" method="post" action="<?php echo site_url('root/administrator/sendinvite'); ?>">
            <div class="control-group">
                <label class="control-label" for="select01">Select Set</label>
                <div class="controls">

                    <select id="select01" class="chzn-select" name="set_code" title="Select the set this student(s) will belong to">
                        <option value="">Select set</option>
                        <?php foreach ($sets as $set) { ?>
                        <option <?php echo set_select('set_code', $set->group_id); ?> value="<?php echo $set->group_id; ?>"><?php echo $set->group_name; ?></option>
                        <?php } ?>
                    <font size="1" color='red'><?php echo form_error('set_code'); ?></font>
            <div class="control-group">
                <label class="control-label" for="multiSelect">Select student(s)</label>
                <div class="controls">
                    <select multiple="multiple" id="multiSelect" name="student_email" class="chzn-select span4" title="Select student(s) for this set">
                        <option value="">Select Student</option>
                        <?php foreach ($students as $student) { ?>
                        <option <?php echo set_select('student_email', $student->uacc_email); ?> value="<?php echo $student->uacc_email; ?>"><?php echo $student->uacc_username; ?></option>
                        <?php } ?>
                    <p class="help-block">Start typing to activate auto complete!</p>
                    <font size="1" color='red'><?php echo form_error('student_email'); ?></font>
                <input type="hidden" name="student_id" value="<?php echo $student->upro_uacc_fk; ?>" class="span6 m-wrap"/>

            <div class="form-actions">
                <button type="submit" class="btn btn-primary">Send code</button>
                <button type="reset" class="btn">Cancel</button>

Below is my Controller, which accepts the selected users and used same to send email:

public function sendinvite() {
    if ($this->input->post()) {

        $this->form_validation->set_rules('student_email', 'Student name', 'required');
        $this->form_validation->set_rules('set_code', 'Set name', 'required');

        if ($this->form_validation->run() == FALSE) {
            $this->data['students'] = $this->super_model->get_members_with_out_group();
            $this->data['sets'] = $this->super_model->get_group_list_for_code_invite();
            $this->data['content'] = 'root/invitestudent';
            $this->load->view('layout/root/template', $this->data);
        } else {
            $config = Array(
                'protocol' => 'smtp',
                'smtp_host' => '',
                'smtp_port' => 25,
                'smtp_user' => 'root', 
                'smtp_pass' => '347y6Z45Rwlfub020', 
                'mailtype' => 'html',
                'charset' => 'iso-8859-1',
                'wordwrap' => TRUE

            $this->load->library('email', $config);
            $len = 8;
            $type = 'HhJjKkMmNnPpQqRrSsTt';
            $set = $this->input->post('set_code');
            //$new_password = rand(34546, 89757);
            $this->email->from('', "Admin Manager");
            $this->email->subject('BSN-Set Code');
            $this->email->message("You are invited to join the group. Your set code is: $set");

            $data['message'] = "Sorry Unable to send email...";
            if ($this->email->send()) {
                $data['message'] = "Mail sent...";
    } else {
        $this->data['students'] = $this->super_model->get_members_with_out_group();
        $this->data['sets'] = $this->super_model->get_group_list_for_code_invite();
        $this->data['content'] = 'root/invitestudent';
        $this->load->view('layout/root/template', $this->data);


Thanks guys in anticipation

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.