codeigniter email->send being send twice

最后都变了- 提交于 2019-12-25 07:36:18

问题


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!


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




回答2:


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.




回答3:


Remove this code

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

from

function _send_email($type, $email, &$data)


来源:https://stackoverflow.com/questions/13971582/codeigniter-email-send-being-send-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!