psab_72
psab_72

Reputation: 51

Codeigniter ion auth forgot password not sending email

If I submit to reset the new password to my email, CodeIgniter is not sending mail. But it's returning a message that Password Reset Email Sent. So it doesn't trigger an error.

I'm using CodeIgniter 2.1.4 and IonAuth 2.5.2

$config['use_ci_email'] = TRUE;

I already set this config to TRUE, and still not sending mail.

Upvotes: 4

Views: 6423

Answers (2)

Maulik Gushani
Maulik Gushani

Reputation: 31

Not change anything in 'ion_auth.php'. file as it is like :

$config['use_ci_email'] = FALSE; // Send Email using the builtin CI email class, if false it will return the code and the identity
$config['email_config'] = array(
    'mailtype' => 'html',
);

and then 'Auth.php' which is controller file in change some code which is like :

if ($forgotten)
            {
                // if there were no errors
//              $this->session->set_flashdata('message', $this->ion_auth->messages());
//              redirect("auth/login"); //we should display a confirmation page here instead of the login page
                            $config = [
                                            'protocol' => 'smtp',
                                            'smtp_host' => 'ssl://smtp.googlemail.com',
                                            'smtp_port' => 465,
                                            'smtp_user' => 'xxx',
                                            'smtp_pass' => 'xxx',
                                            'mailtype' => 'html'
                                        ];
                            $data = array(
                                'identity'=>$forgotten['identity'],
                                'forgotten_password_code' => $forgotten['forgotten_password_code'],
                            );
                            $this->load->library('email');
                            $this->email->initialize($config);
                            $this->load->helpers('url');
                            $this->email->set_newline("\r\n");

                            $this->email->from('xxx');
                            $this->email->to("xxx");
                            $this->email->subject("forgot password");
                            $body = $this->load->view('auth/email/forgot_password.tpl.php',$data,TRUE);
                            $this->email->message($body);

                            if ($this->email->send()) {

                                $this->session->set_flashdata('success','Email Send sucessfully');
                                return redirect('auth/login');
                            } 
                            else {
                                echo "Email not send .....";
                                show_error($this->email->print_debugger());
                            }
            }
            else
            {
                $this->session->set_flashdata('message', $this->ion_auth->errors());
                redirect("auth/forgot_password");
            }

Upvotes: 1

tungbk29
tungbk29

Reputation: 86

I use config in codeigniter application/config/email.php

$config['protocol'] = 'mail';
$config['wordwrap'] = false;
$config['mailtype'] = 'html';

application/config/autoload.php

$autoload['libraries'] = array('lang','template', 'email','form_validation','session','encrypt','pagination','upload','database' );

In controller

$this->email->from(MAIL,MAIL);
$this->email->to($mailto);
$this->email->subject($text_subject);
$this->email->message($this->load->view('email/template_email',$data,TRUE));
$this->email->send();

Upvotes: 0

Related Questions