codeigniter email->发送两次发送

时间:2012-12-20 11:49:56

标签: codeigniter email

我正在使用codeigniter 2和tank_auth库。 在名为user_model的模型中,它有一个函数(_send_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";
    }
}

我尝试从这样的控制器调用此函数:

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 
}

问题是电子邮件被发送两次到电子邮件地址

任何遇到此问题的人都知道在哪里寻找解决方案(或问题)

更多信息:

我正在尝试在我的控制器中创建一个方法,就像使用指南中的示例一样: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();

此方法还会发送两次电子邮件!

3 个答案:

答案 0 :(得分:1)

原因是我有适用于Google Chrome的插件Firebug Lite。在我停用此页面后,只请求一次! 在这里发现了awnser: https://stackoverflow.com/a/10580841/1108772

感谢大家的回复和所有帮助

答案 1 :(得分:0)

删除此代码

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

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

答案 2 :(得分:0)

首先,这是错误的做法。仅使用模型功能与数据库交互。发送邮件的功能应该在控制器中。