2017-02-15 2 views
0

У меня есть одна форму выбора в моем приложении .. в том, что я получаю список пользователей из таблицы пользователей в поле выбора. Я пытаюсь отправить почту в зависимости от выбранный пользователь из раскрывающегося списка .. Я получил user_id из раскрывающегося списка .. но я не получил электронную почту. Я много пробовал, но я не нашел, где я получил ошибку.отправить почту из зависимости от выбранного пользователя в codeigniter

Вот мой контроллер :

общественная функция add_selection() {

$data["msg"]=""; 
$this->load->model('SelectionModel'); 
$data['rolename']=$this->SelectionModel->getrolename(); 
$data['candidate']=$this->SelectionModel->getcandidates(); 
$data['usertype']=$this->SelectionModel->getusers(); 

если ($ this-> вход-> пост())

{ 

    $this->SelectionModel->add_selection_details($this->input->post()); 
$all_users = $this->input->post('user_id'); 
print_r($all_users); 
     foreach($all_users as $key) 
     { 
     $get_email = $this->SelectionModel->get_user_email_by_id($key); 

     $config = Array(
      'protocol' => 'smtp', 
      'smtp_host' => 'ssl://md-in-42.webhostbox.net', 
      'smtp_port' => 465, 
      'smtp_user' => '[email protected]', 
      'smtp_pass' => 'test3' 
    ); 
     $this->load->library('email',$config); 
     $this->email->set_mailtype("html"); 
     $this->email->from('[email protected]', 'bharathi'); 
     $this->email->to($get_email); 
     $this->email->subject('this is our candidate details pls go through it'); 
     $link = 'Click on this link - <a href="http://localhost/job_portal/index.php/Login/signin">Click Here</a>'; 
     $this->email->message($link); 
     print_r($get_email); 
     if($this->email->send()) 
     { 

       echo "email sent"; 
      } 
      else 
      { 
       echo "email failed"; 
      } 


} 

}

$this->load->view('selection/selection_details',$data); 

}

Это моя модель:

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']; 

}

, пожалуйста, помогите мне, как это сделать .. Спасибо ..

+0

Что выводится на 'print_r ($ all_users); '? –

+0

it display user_id – M5533

+0

Я пытаюсь получить этот адрес user_id .. но он не работает. – M5533

ответ

1

В вашей модели. Попробуйте один раз, как это ..

function get_user_email_by_id($user_id) 
    { 
    $this->db->select('email'); 
    $this->db->from('users'); 
    $this->db->where('user_id',$user_id); 
    $query = $this->db->get(); 
    return $query->row()->email; 
    } 

Ввиду:

<select class="form-control" multiple class="form-control" data-placeholder="user name" name="user_id[]" > 
<?php foreach($usertype as $rows) { ?> 
<option value="<?php echo $rows->user_id?>"><?php echo ucfirst($rows->first_name)?></option> 
<?php } ?> 
+0

Попробуйте отредактировать ответ для одного пользователя. Вам нужно показать свою часть просмотра, как вы выбираете многопользовательский режим в раскрывающемся меню. –

+0