I am using codeigniters email class inside an Expression Engine plugin (EE runs off CI). For some reason each time the plugin is run it sends out 2 emails, instead of 1. The emails are identical.
{exp:cdwd_emailer:questionnaire type="{segment_3}" entry_id="{segment_4}"}
Here is the function being called by the above.
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 protected]';
$fromName = 'Test Name';
$toEmail = '[email protected]';
$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();
}
Can anyone tell me why? I can't figure it out. I printed out the contents of the type and entry_id params to check only 1 of each are being collected.
Thanks
I think you have to clear you email object after sending mail. As per Expression Engine, you have to call:
ee()->email->clear();
For your case:
$this->EE->email->clear();