Email and loops error. |
[eluser]schnoodles[/eluser]
hello, i am currently doing. function send_emails() { $this->load->library('email'); $this->lang->load('sentry'); $this->load->model('UserInvitesModel'); $user = new UserInvitesModel(); $invites = $user->get_invites(); if ( sizeof( $invites ) > 0 ) { foreach( $invites as $value ) { echo $value->id.'<br />'; $this->email->clear(); $this->email->from('[email protected]', $value->username); $this->email->to($value->email); $this->email->subject($value->username.' has invited you to join a new mobile experience'); $this->email->message($this->lang->line('sentry_invitation_message').'\r\n\r\n'.$value->username); if ( $this->email->send()) { $users = $user->find($value->id); $users->delete(); } } } } Where $invites = $user->get_invites(); grabs all invites and add them to an array. This works perfect except for the EMAIL part. It only seems to loop once, then errors the email class :\ ATM what it echos on the page is 5 [email protected] 6 Fatal error: Call to a member function clear() on a non-object in /trunk/application/controllers/upload.php on line 29 Line 29 was $this->email->clear(); ofcourse.
[eluser]coolfactor[/eluser]
Obviously, the Email class is not being loaded. That's where you need to focus. What are your server specs? Try the following approach: Code: $CI =& get_instance(); On some servers, $this is broken. By the way, please wrap your code examples in [ code ] and [/ code ] tags (without the spaces). Makes it easier to read.
[eluser]schnoodles[/eluser]
OK $this does work for one loop, it just seems that the second iteration for some reason it 'unsets' so i ended up just doing Code: $email = $this->email; Before the loop and just use $email->clear() and what not and it worked. Even though i shouldnt of had to do this, it was just a weird error and ive never even seen it happen before.
[eluser]Daniel H[/eluser]
I am experiencing this problem too - is there a proper solution to it? |
Welcome Guest, Not a member yet? Register Sign In |