【问题标题】:send mail from depending on the selected user in codeigniter根据在codeigniter中选择的用户发送邮件
【发布时间】:2017-02-15 05:28:13
【问题描述】:

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

这是我的控制器:

公共函数 add_selection() {

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

if($this->input->post())

{

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

}

请帮助我如何做到这一点.. 谢谢。。

【问题讨论】:

  • `print_r($all_users);' 上的输出是什么?
  • 显示user_id
  • 我正在尝试获取该 user_id 电子邮件..但它不起作用..
  • id 数组还是只有一个 id?
  • 它只显示一个 id..但我想要 id 的数组..它显示在用户预览中..但它没有存储在数据库中

标签: codeigniter email


【解决方案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 } ?>

【讨论】:

  • 尝试为单个用户编辑答案。您需要显示您的视图部分,以了解如何在下拉列表中选择多用户。
  • 更改name="user_id[]"。并以与在控制器中尝试相同的方式尝试。
  • @M5533 很高兴为您提供帮助。祝您好运。
  • 我可以这样使用 $list=array('nalamalapu.bharathi@gmail.com','bharathi.nalamalapu@gmail.com');$this->email->to($get_email ,$list);
【解决方案2】:

当您选择多个值时,尝试通过 select 获取数组中的值!名称="选择[]"

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";
          }


}
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-27
    • 1970-01-01
    • 1970-01-01
    • 2019-08-26
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多