Welcome Guest, Not a member yet? Register   Sign In
Email and loops error.
#1

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

[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();
$CI->load->library('email');
// and then...
$CI->email->clear();

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.
#3

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

[eluser]Daniel H[/eluser]
I am experiencing this problem too - is there a proper solution to it?




Theme © iAndrew 2016 - Forum software by © MyBB