根据codeigniter中所选用户发送邮件

时间:2017-02-15 05:28:13

标签: codeigniter email

我在我的应用程序中有一个选择表单。我从选择框中的用户表中获取用户列表下拉..我正在尝试根据所选用户从下拉列表发送邮件。 我从下拉菜单中获得了user_id ..但是我没有收到电子邮件..我尝试了很多,但我没有找到错误的地方..

这是我的控制器:

public function add_selection() {

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

如果($这 - >输入 - >柱())

{

  $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' => 'test3@clozloop.com',
          'smtp_pass' => 'test3'
      );
         $this->load->library('email',$config);
         $this->email->set_mailtype("html");
         $this->email->from('test3@clozloop.com', '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'];

}

请帮我怎么做.. 谢谢..

2 个答案:

答案 0 :(得分: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 } ?>

答案 1 :(得分:0)

尝试通过select获取数组中的值,同时多次选择值! NAME = “选择[]”

if(count($this->input->post()) > 0) {

  $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' => 'test3@clozloop.com',
          'smtp_pass' => 'test3',
          'mailtype' => 'html',
          'charset' => 'iso-8859-1',
          'wordwrap' => 'TRUE',
          'newline' => '\r\n'
      );
         $this->load->library('email',$config);
         $this->email->set_mailtype("html");
         $this->email->from('test3@clozloop.com', '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";
          }


}
}