0

i am using codeigniter 2 with the tank_auth library. in the model named user_model it has an function (_send_email()) to send an email:

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

    $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 "sendit";
    }
}

i try to call this function from a controller like this:

public function email($value='')
{
    $this->lang->load('tank_auth', 'dutch');
    $this->load->model('user_model');
    $data = array("site_name" => "site name");
    $this->user_model->_send_email('bestelling_geplaatst', "my_email@hotmail.com",$data); // send 
}

the problem is that the email is being sent twice to the email adres

anyone who run across this problem an know's where to look for an solution ( or the problem)

More info:

i am trying to make a method in my controller just like the example in the use guide like here: https://www.codeigniter.com/user_guide/libraries/email.html

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

$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com'); 
$this->email->cc('another@another-example.com'); 
$this->email->bcc('them@their-example.com'); 

$this->email->subject('Email Test');
$this->email->message('Testing the email class.');  

$this->email->send();

This method also sends the email twice!

Stack Programmer
  • 679
  • 6
  • 18
This_is_me
  • 908
  • 9
  • 20
  • May be your email function is called twice ... check properly. – Sachin Prasad Dec 21 '12 at 11:55
  • thnx for reply, i found my awnser i was looking for, the problem was the Firebug Lite for Google Chrome as i described here: http://stackoverflow.com/a/13972704/1108772 – This_is_me Dec 21 '12 at 12:34

3 Answers3

1

The reason is i have the plugin Firebug Lite for Google Chrome. after i deactivated this the page only requested once! found awnser right here: https://stackoverflow.com/a/10580841/1108772

Thanks everyone for replying and all you help

Community
  • 1
  • 1
This_is_me
  • 908
  • 9
  • 20
0

Remove this code

if($this->email->send())
{
    echo "sendit";
}

from

function _send_email($type, $email, &$data)
Kasun
  • 679
  • 1
  • 7
  • 21
Faizan Khattak
  • 862
  • 8
  • 22
0

First of all, This is wrong approach. Use model function only to interactive with database. The function that sends the mail should be in controller.

Deep123
  • 391
  • 1
  • 5
  • 18