【问题标题】:fetch email from id and send mail to that particular user in codeigniter从 id 获取电子邮件并将邮件发送给 codeigniter 中的特定用户
【发布时间】:2023-03-21 11:41:02
【问题描述】:

我的应用程序中有一个查看候选人表格 ..in 显示所有候选人详细信息,并且我还显示 user_id ..我在视图页面中给出了名为发送的按钮..

所以我正在尝试的是,当我单击按钮时,我需要获取用户电子邮件并将邮件发送给该用户..

查看代码:

<section class="content">
  <div class="row">
    <div class="col-xs-12">

        <!-- /.box-header -->
        <div class="box-body">
          <table id="example2" class="table table-bordered table-hover">
            <thead>
              <tr>
              <th></th>
              <th>Vendor</th>
              <th>First Name</th>
               <th>Last Name</th> 
              <th>Email</th>
              <th>Mobile Number</th>
              <th>experience</th>
              <th>CTC</th>
              <th>Expected Ctc</th>
              <th>role</th>
              <th>Current Location</th>
              <th>Desired Location</th>
              <th>Notice Period</th>
               <th>Resume</th>
              <th>Actions</th>


            </tr>
            </thead>

             <?php 

               foreach ($view_candidates as $idata) 
                {
                ?>


            <tbody>



               <tr id="domain<?php echo $idata->user_id;?>">
                   <td class="cell checkbox">
                <input type="checkbox" class="selectedId" name="selectedId" />
                   </td>

                    <td><?php echo $idata->user_id;?></td>
                    <td><?php echo $idata->first_name;?></td>
                    <td><?php echo $idata->last_name;?></td>  
                    <td><?php echo $idata->email;?></td>
                    <td><?php echo $idata->mobile_number;?></td>
                    <td><?php echo $idata->experience;?></td>
                    <td><?php echo $idata->ctc;?></td>
                    <td><?php echo $idata->expectedctc;?></td>
                    <td><?php echo $idata->role_name;?></td>
                    <td><?php echo $idata->current_location;?></td>
                    <td><?php echo $idata->desired_location;?></td>
                    <td><?php echo $idata->notice_period;?></td>
                    <td><?php echo $idata->resume;?></td>

                  <td><button id="<?php echo $idata->candidate_id; ?>" name="button" onClick="CallFunction(this.id)"  class="btn btn-info">send</button></td>
             </tr>

            <?php
          }
            ?>


            </tbody>

控制器:

public function change_status()

{

$candidate_id = $this->input->post('candidate_id');
$this->CandidateModel->update_status($candidate_id);
   $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('someone@gmail.com'); 

          $this->email->subject('Request for contact info');
         $link = 'Click on this link - <a href="http://localhost/job_portal/index.php/Login/signin?requirement_id=29">Click Here</a>';
         $this->email->message($link);

           if($this->email->send())
           {
              echo "email send";
           }

         else
         {
          echo "failed";
         }
// echo true;
// exit;

}

型号:

function  update_status($candidate_id)

{

$this->db->select('*');
$this->db->from('candidates_details');
 $status = $this->db->query("update candidates_details set status='1'  where candidate_id ='$candidate_id'");
$data=array('status'=>$status);
$this->db->where('candidate_id',$candidate_id);
//$this->db->update('candidates_details',$data);
//$query=$this->db->get();
echo $this->db->last_query();
//return $query->result();

}

谁能帮助我如何向该用户发送邮件..

提前谢谢..

【问题讨论】:

  • ya..发生的事情是我已经在使用 ajax 调用..同时单击按钮而不刷新任何内容..我将数据库值 0 中的状态更新为 1..
  • 我不知道如何获取该用户的电子邮件..请解释一下..如何做到这一点..
  • 发布你的 ajax 代码

标签: codeigniter email


【解决方案1】:

执行以下操作:

<script>
  function CallFunction(id){
    var url = '127.0.0.1/job_portal/index.php/Candidate/change_status/'‌​;;
    $.ajax({
      url: url,
      type: 'POST',
      data: {
        candidate_id: id
      },
      dataType: 'JSON',
      success: function(data) {
        if(data == 1) {
          $('.button').text('FINISHED');
        } else {
          $('.button').text('TRY AGAIN!');
        }
      }
    });
  }
</script>

控制器和模型:

<?php
    // controller

function change_status()
{
  $data = $_POST;
  $d = $this->user_model->send_email($data['candidate_id']);
  echo json_encode($d);
}

    // model

function send_email($candidate_id)
{
  $q = $this->db->query("SELECT u.email_id as email_id FROM tbl_candidate as c, tbl_user as u WHERE c.candidate_id = $candidate_id AND c.user_id = u.user_id");
  if($q->num_rows() > 0) {
    $d = $q->row_array();
    $to = $d['email_id'];
    $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($to);

    $this->email->subject('Request for contact info');
    $link = 'Click on this link - <a href="http://localhost/job_portal/index.php/Login/signin?requirement_id=29">Click Here</a>';
    $this->email->message($link);

    if($this->email->send())
    {
      return 1;
    }
    else
    {
      return 0;
    }
  } else {
    return 0;
  }
}

?>

【讨论】:

  • 评论不用于扩展讨论;这个对话是moved to chat
  • @Pathik Vejani 成功函数在 ajax 中不起作用.. 成功:function(data) { if(data == 1) { $('.button').text('FINISHED'); } else { $('.button').text('再试一次!'); }
  • @Pathik Vejani ..ajax 成功功能不起作用..所以这就是昨天我这样做的原因..所以当我这样做时..这封电子邮件不起作用..
  • @user3663 ajax 和电子邮件不工作之间没有联系。一定是你这边出了点问题
  • 是的..我昨天刷新了页面..所以如果页面刷新正常,电子邮件不工作......如果页面刷新不工作..然后电子邮件工作..为什么会发生..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-16
  • 2018-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多