-1

I have two tables in my database one is users and another one is requirements..so I displayed user names in the requirements form with multiple select dropdown..when admin send requirements from the requirement form...I need to send that requirement to particular users..with selected by the admin from the dropdown..

this is my controller :

 public function requirement() {
     $this->load->model('RequirementModel');
     $data['user']=$this->RequirementModel->getusers();

     $this->load->view('Requirements/requirements',$data);

     $insert=array(
         'role_name'=>$this->input->post('role_name'),
         'vacancies'=>$this->input->post('vacancies'),
         'experience'=>$this->input->post('experience'),
         'jd'=>$this->input->post('jd'),
         'hiring_contact_name'=>$this->input->post('hiring_contact_name'),
         'hiring_contact_number'=>$this->input->post('hiring_contact_number'),
         'user_id'=> implode(',',$this->input->post('user_id'))
     );
     $this->RequirementModel->add_requirement($insert);
 }

Please help me how can we send mail to the particular users.. Thank You

Manoj Sharma
  • 1,467
  • 2
  • 13
  • 20
M5533
  • 117
  • 2
  • 3
  • 13

1 Answers1

0

This must be your HTML code in your view file.

<select id='user' name="user">
    <option value="">Please Select Name</option>
    <?php foreach($user as $val){ ?>
    <option value="<?php echo $val['id'];?>" ><?php echo $val['name']?></option>
    <?php } ?>
</select>

In your controller you can get user id by POST method $this->input->post('user');

Create a model function to retrieve user email by user id get_user_email_by_id then call the model to get the email of the selected user.

$this->your_model->get_user_email_by_id($this->input->post('user'));

After that you can send the email to the selected user.

Update

You want to send email to multiple number of users, this was not specified by you earlier Try to be specific for the requirement. Get multiple user id in a variable.

$all_users = $this->input->post('user_id');

foreach($all_users as $key)
{
  $get_email = $this->your_model->get_user_email_by_id($key);
  // write function to send email
}

Model Function to get user email by id:

function get_user_email_by_id($user_id) 
{ 
  $this->db->select('*'); 
  $this->db->from('users'); 
  $this->db->where('user_id',$user_id); 
  $query = $this->db->get(); 
  $result = $query->row_array();
  return $result['email'];
}
Happy Coding
  • 2,517
  • 1
  • 13
  • 24
  • ok thank you @Happy Coding..today i learn how to send mail..because of you only..thank you thanks alot.. – M5533 Feb 08 '17 at 07:06