Codeigniter发送多封电子邮件

时间:2014-01-13 11:43:38

标签: codeigniter email expressionengine

我在Expression Engine插件中使用codeigniters电子邮件类(EE运行CI)。 出于某种原因,每次插件运行时,它会发送2封电子邮件,而不是1.电子邮件是相同的。

{exp:cdwd_emailer:questionnaire type="{segment_3}" entry_id="{segment_4}"}

以下是上述调用的函数。

public function questionnaire() {

    $type = $this->EE->TMPL->fetch_param('type');
    $typeLower = str_replace("-", " ", $type);
    $typeUpper = ucwords($typeLower);

    print_r($type);

    $entry_id = $this->EE->TMPL->fetch_param('entry_id');

    $subject = $typeUpper.' Questionnaire Submission';
    $fromEmail = 'email@email.com';
    $fromName = 'Test Name';
    $toEmail = 'email@email.com';

    $message = '
        <p>A new '.$typeLower.' has been submitted.</p>
        <p><a href="http://www.domain.co.uk/questionnaires/view/'.$type.'/'.$entry_id.'">Please click here to view this submission</a></p>
    ';

    $this->EE->load->library('email');
    $this->EE->email->set_mailtype("html");         
    $this->EE->email->from($fromEmail, $fromName);
    $this->EE->email->to($toEmail);     
    $this->EE->email->subject($subject);
    $this->EE->email->message($message);
    $this->EE->email->send();

}

谁能告诉我为什么?我无法弄清楚。我打印出了类型和entry_id参数的内容,以便只检查每个中的1个。

由于

1 个答案:

答案 0 :(得分:2)

我认为您必须在发送邮件后清除电子邮件主题。 根据Expressionengine,您必须致电:

 ee()->email->clear();

对于你的情况:

$this->EE->email->clear();