未发送Codeigniter电子邮件

时间:2015-08-23 10:48:20

标签: php codeigniter email

我有一个Codeigniter表单,如下所示:

CI form

当我点击“批准”的绿色复选标记或“拒绝”的红色十字标志时,应该会将电子邮件发送到某些地址。但我已经检查过邮件从未发送过。

为了更好地理解,以下是我的一些代码:

查看:

<td class="center">
                <?php
                $edit_text = (ACTION_BUTTON_TEXT_SHOW) ? 'Approve' : '&nbsp;';
                echo anchor('staff_requisitions/update_approve/' . $row['id'],"<img src='".base_url()."/media/images/accept.png'>", $edit_text, array('class' => 'edit_button', 'title' => 'Approve'));
                ?>
</td>
<td class="center">
                <?php
                $edit_text = (ACTION_BUTTON_TEXT_SHOW) ? 'Reject' : '&nbsp;';
                echo anchor('staff_requisitions/update_reject/' . $row['id'],"<img src='".base_url()."/media/images/reject.png'>", $edit_text, array('class' => 'edit_button', 'title' => 'Reject'));
                ?>
</td>

控制器:

function __construct()
{
    parent::__construct();
    $this->load->database();
    $this->load->model('Staff_requisition');
    $this->load->helper('url');
    $this->load->helper('html');
    $this->load->helper('form');
    $this->load->library('email');
    $this->output->enable_profiler(false);
}

function update_approve(){
    $id = $this->uri->segment(3);
    $this->Staff_requisition->update_approve($id);
    //$data['list_of_emails'] = $this->Staff_requisition->get_list_of_emails($id);
    $this->email->from('joshamee_gibbs@example.com', 'Joshamee');
    $this->email->to('capn_jack_sparrow@example.com');
    $this->email->cc('william.turner1724@example.com');
    $this->email->subject('Email Test');
    $this->email->message('Testing the email class. Your requisition approved.');
    $this->email->send();
    echo $this->email->print_debugger();
    $this->session->set_flashdata('message', 'The requisition request has been approved');
    redirect('staff_requisitions/index');
}

function update_reject(){
    $id = $this->uri->segment(3);
    $this->Staff_requisition->update_reject($id);
    //$data['list_of_emails'] = $this->Staff_requisition->get_list_of_emails($id);
    $this->email->from('joshamee_gibbs@example.com', 'Joshamee');
    $this->email->to('capn_jack_sparrow@example.com');
    $this->email->cc('william.turner1724@example.com');
    $this->email->subject('Email Test');
    $this->email->message('Testing the email class. Your requisition rejected.');
    $this->email->send();
    echo $this->email->print_debugger();
    $this->session->set_flashdata('message', 'Sorry, the requisition request has been rejected');
    redirect('staff_requisitions/index');
}

型号:

function __construct()
{
    parent::__construct();
}

function update_approve($rid){
        $this->db->query("UPDATE `staff_requisitions` SET `is_approve` = 1 WHERE `id` = $rid ");
}

function update_reject($rid){
    $this->db->query("UPDATE `staff_requisitions` SET `is_approve` = 0 WHERE `id` = $rid ");
}

function get_list_of_emails($id){
    $q = $this->db->query("SELECT * FROM `requisition_emails` WHERE `req_id` = $id")->result_array();
    return $q;
}

我错过了什么/做错了什么?

N.b。我在localhost中运行此应用程序。

1 个答案:

答案 0 :(得分:1)

使用此设置

public $smtp = array(
  'transport' => 'Smtp',
  'from' => 'your_mail@gmail.com',
  'host' => 'ssl://smtp.gmail.com',
  'port' => 465,
  'timeout' => 30,
  'username' => 'your_mail@gmail.com',
  'password' => '*****'
)