0

I have a Codeigniter form like the following:

CI form

When I click on the green check sign for "Approve" or the red cross sign for "Reject" , an email is supposed to be sent to certain addresses. But I've checked that the mail was never sent.

For better understanding, here are some of my codes:

View:

<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>

Controller:

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');
}

Model:

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

What am I missing/doing wrong?

N.b. I'm running this application in localhost.

AD7six
  • 63,116
  • 12
  • 91
  • 123

1 Answers1

1

Use this setting

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' => '*****'
)
Drop Shadow
  • 845
  • 3
  • 12
  • 28
  • In your php mailer settings file – Drop Shadow Aug 23 '15 at 11:17
  • Can you please specify where this file is situated? Is it the php.ini in wamp root folder? – Choudhury Saadmaan Mahmid Aug 23 '15 at 11:27
  • ok just write a new function and try it : $mail = new PHPMailer(true); // create a new object $mail->IsHTML(true); $mail->IsSMTP(); $mail->SMTPDebug = 1; $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; $mail->Host = "smtp.gmail.com"; $mail->Port = 465; //465 or 587 $mail->IsHTML(true); $mail->Username = "user@gmail.com"; $mail->Password = ""; $mail->SetFrom("user@gmail.com"); $mail->Subject = "your subject "; $mail->Body = $mailBody; $mail->Send(); – Drop Shadow Aug 23 '15 at 11:31
  • And which address should I sent this mail to? You didn't mention a SetTo() or something similar. – Choudhury Saadmaan Mahmid Aug 23 '15 at 11:38
  • $mail->AddAddress('sendTo@gmail.com'); – Drop Shadow Aug 23 '15 at 11:41