我在我的应用程序中有一个候选人形式..我显示了所有候选人的详细信息,并且我显示了user_id也..在视图页面中给出了名为send的按钮..
所以我正在尝试的是当我点击按钮时我需要获取用户电子邮件并向该用户发送邮件..
查看代码:
<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();
}
任何人都可以帮助我如何向该用户发送邮件..
提前致谢..
答案 0 :(得分:0)
执行以下操作:
<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;
}
}
?>