我有一个多选下拉菜单,允许我一次选择多个用户。我希望能够选择多个用户,当我点击"发送代码"按钮,应用程序将使用电子邮件地址向这些用户发送电子邮件。目前,当我选择并单击"发送代码"时,应用程序将仅向一个用户发送电子邮件而只留一次。我想知道一次向所有选定的用户发送电子邮件。我使用CodeIgniter,下面是我的代码:
以下是我的代码的视图部分,它允许用户选择用户并发送代码:
<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>
以下是我的Controller,它接受所选用户并使用它来发送电子邮件:
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('admin@passwordmanager.com', "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);
}
}
答案 0 :(得分:0)
你可以像这样使用
// Array ( [0] => c@gmail.com [1] => a@gmail.com [2] => b@gamil.com )
$addresses = implode(',',$this->input->post('student_email');
// c@gmail.com,a@gmail.com,b@gamil.com
$this->email->to($addresses);