CodeIgniter Forums
Email - Sending Twice on single send? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Email - Sending Twice on single send? (/showthread.php?tid=6660)



Email - Sending Twice on single send? - El Forum - 03-06-2008

[eluser]nevsie[/eluser]
Not sure why, but playing with some rough code for a callback from a form to send an email. Simple and easy enough... however the email arrives twice!!! any idea folks?

Code:
function send_email($email)
    {
        $this->db->select('id, email');
        $query = $this->db->get_where('users', array('email'=>$email), 1, 0);
        if ($query->num_rows != 1) {
            $this->validation->set_message('send_email', 'Email Address is not registered here, sorry!!!');
            return FALSE;
        } else {
            $row = $query->row();
            
            $this->load->library('email');

            $this->email->from('[email protected]', 'Email Admin');
            $this->email->to($row->email);

            $this->email->subject('Reset Your Password');
            $this->email->message('Testing the email class. numrows='.$query->num_rows.' emailaddy='.$row->email.' end');

            if ($this->email->send())
            {
                return TRUE;
            }
            else
            {
                $this->validation->set_message('send_email', 'Email could not be sent!!!');
                return FALSE;
            }
        }
        
    }



Email - Sending Twice on single send? - El Forum - 01-10-2009

[eluser]eriksays[/eluser]
did you ever get this issue resolved? i'm experiencing this as well.


Email - Sending Twice on single send? - El Forum - 09-03-2010

[eluser]Pschilly[/eluser]
I am also having this issue... No resolution to speak of.


Email - Sending Twice on single send? - El Forum - 09-03-2010

[eluser]eriksays[/eluser]
I did not diagnose the "why", but I did discover the "what".

basically -- the send() was being fired twice -- once at the controller layer, and once at the view layer. Even though I didn't have any views being loaded, the application was still loading a default view and firing the send() call at that time as well.

by putting a die() at the end of this function, I resolved my problem. I realize that's pretty hackalicious but for me, this particular function is not ever part of the view cycle anyway, it's a weekly automated message routine.

if that solution doesn't work for you, perhaps taking the mail functions out of the controller layer or diagnosing further is always an option, too.