DanielAttard
DanielAttard

Reputation: 3615

PHP & jQuery sending duplicate copies of email messages

I am trying to figure out why my users are receiving duplicate copies of email messages being sent from my web application. Here is the code which sends the email:

function _send_user_email($to, $subject, $message) {
    $this->load->library('email');
    $config['charset'] = 'utf-8';
    $config['wordwrap'] = TRUE;
    $config['mailtype'] = 'html';    
    $config['protocol'] = 'sendmail';
    $this->email->initialize($config);
    $this->email->from('[email protected]', 'Customer Service');
    $this->email->reply_to('[email protected]', 'Customer Service');
    $this->email->to($to);
    $this->email->bcc('[email protected]');
    $this->email->subject($subject);
    $this->email->message($message);
    $this->email->send();
    if ( ! $this->email->send())
    {
        echo $this->email->print_debugger();
        exit;
    } 
} 

Is there anything wrong with this code that might be causing the message to be sent twice?

Upvotes: 1

Views: 81

Answers (1)

Marko D
Marko D

Reputation: 7576

Obviously, because of

$this->email->send();
    if ( ! $this->email->send())

You are sending email twice. Remove the first call, leave only the one in if statement

Upvotes: 6

Related Questions