2016-12-28 159 views
0

我有一个多选下拉菜单,允许我一次选择多个用户。我希望能够选择多个用户,当我点击“发送代码”按钮时,应用程序将下载使用电子邮件地址向这些用户发送电子邮件。目前,当我选择并点击“发送代码”时,应用程序将只发送电子邮件给只有一个用户离开一次。请我想知道一次向所有选定的用户发送电子邮件。我使用笨以下是我的代码:使用codeigniter从多选选项发送电子邮件到多个地址-PHP

下面是我的代码视图部分,它使用户能够选择用户并发送代码:

<head> 
    <meta charset="UTF-8"> 
    <title>Member Invite</title> 
</head> 
<body> 
    <form class="form-horizontal" method="post" action="<?php echo site_url('root/administrator/sendinvite'); ?>"> 
     <fieldset> 
      <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 } ?> 
        </select> 
        <font size="1" color='red'><?php echo form_error('set_code'); ?></font> 
       </div> 
      </div> 
      <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 } ?> 
        </select> 
        <p class="help-block">Start typing to activate auto complete!</p> 
        <font size="1" color='red'><?php echo form_error('student_email'); ?></font> 
       </div> 
       <input type="hidden" name="student_id" value="<?php echo $student->upro_uacc_fk; ?>" class="span6 m-wrap"/> 

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

下面是我的控制器,它接受的选择并使用相同的用户发送电子邮件:

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' => 'mail.mydomain.com', 
       '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('[email protected]', "Admin Manager"); 
      $this->email->to($this->input->post('student_email')); 
      //$this->email->cc($this->input->post('student_email')); 
      $this->email->subject('BSN-Set Code'); 
      //$this->flexi_auth->forgotten_password($identity); 
      $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..."; 
      } 
      redirect('root/administrator/invitesuccess'); 
     } 
    } 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); 
    } 
} 

Image is here

回答

相关问题