Kapil Sharma
Kapil Sharma

Reputation: 10417

CodeIgniter tankauth not working with GMail

I've WAMP server setup on local dev environment (php_openssl extension enabled). I installed Code Igniter and trying to configure TankAuth, where I want to use GMail (actually Google Apps) to send test mails.

I went through following URLs for configuration

Based on input from above, I updated _send_email function of tank auth as follow

function _send_email($type, $email, &$data)
{
    $this->load->library('email');

    $config['protocol'] = "smtp";
    $config['smtp_host'] = "ssl://smtp.googlemail.com";
    $config['smtp_port'] = "465";
    $config['smtp_user'] = "[email protected]";//also valid for Google Apps Accounts
    $config['smtp_pass'] = "mypass";
    $config['charset'] = "utf-8";
    $config['mailtype'] = "html";
    $config['newline'] = "\r\n";

    $this->email->initialize($config); 

    $this->email->from($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
    $this->email->reply_to($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
    $this->email->to($email);
    $this->email->subject(sprintf($this->lang->line('auth_subject_'.$type), $this->config->item('website_name', 'tank_auth')));
    $this->email->message($this->load->view('email/'.$type.'-html', $data, TRUE));
    $this->email->set_alt_message($this->load->view('email/'.$type.'-txt', $data, TRUE));
    //$this->email->send();

    if ( ! $this->email->send())
    {
        show_error($this->email->print_debugger());
    } else {
        //echo('DONE');        
    } 
}

I'm getting message mail sent.. but actually mail was not sent. Can someone please point-out where I'm doing the mistake?

Popup is also enabled in GMail settings

Upvotes: 2

Views: 1170

Answers (3)

Keyslinger
Keyslinger

Reputation: 5274

I had the same problem. The following _send_email function, along with removing /application/config/email.php, worked for me:

function _send_email($type, $email, &$data)
{       
    $config['protocol'] = 'smtp'; 
    $config['smtp_host'] = 'ssl://smtp.googlemail.com'; 
    $config['smtp_port'] = 465; 
    $config['smtp_user'] = '[email protected]'; 
    $config['smtp_pass'] = 'NiceTry'; 
    $config['mailtype'] = 'html';

    $this->load->library('email', $config); 

    $this->email->set_newline("\r\n"); 

    $this->email->from($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
    $this->email->reply_to($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
    $this->email->to($email);
    $this->email->subject(sprintf($this->lang->line('auth_subject_'.$type), $this->config->item('website_name', 'tank_auth')));
    $this->email->message($this->load->view('email/'.$type.'-html', $data, TRUE));
    $this->email->set_alt_message($this->load->view('email/'.$type.'-txt', $data, TRUE));

    if ($this->email->send()) { 
        echo "Sent!"; 
    } else { 
        echo "FAILED"; 
    } 

}

Tank Auth Email Problem got me started down the right path.

Upvotes: 0

Mahmoud Ibrahim
Mahmoud Ibrahim

Reputation: 11

Do not edit the _send_email function in Tank Auth. Instead add

$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.googlemail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "[email protected]";//also valid for Google Apps Accounts
$config['smtp_pass'] = "mypass";

to the file "email.php" in your "config" folder.

This worked for me

Upvotes: 1

RamiroRS
RamiroRS

Reputation: 461

Did you check logs to see if an error es loged?

I use postmark to handle all mail delivery, they have some free sends and also there is a spark for CI.

I use in my setup start for new projects. check it:

https://github.com/ramirors/DD-Auth

Upvotes: 0

Related Questions