Welcome Guest, Not a member yet? Register   Sign In
Email - Sending Twice on single send?
#1

[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;
            }
        }
        
    }
#2

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

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

[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.




Theme © iAndrew 2016 - Forum software by © MyBB