Welcome Guest, Not a member yet? Register   Sign In
Email Class: Setting preferences in a loop
#1

[eluser]Dan Bowling[/eluser]
I wrote some code a while ago that loops through queued emails in a database and sends them as plain text. Now, I have to send some as html email.

I have a loop that goes through the chunk of emails and processes each one (might be html, might be plain text). Is there anything technically wrong with the following (initializing the config on each loop)?

Code:
foreach ($emails as $email)
        {
            
        
            $this->email->clear();
            
            $this->email->from($email->from_email, $email->from_name);
            $this->email->to($email->to);
            $this->email->subject($email->subject);
            
            
            //is it an html, or a plain text email?
            if($email->html){
                //there is content in the html field of the email, let's send as an html email
                $config['mailtype'] = 'html';
                $this->email->initialize($config);
                $this->email->message($email->html);    

                
            }
            else
            {
                //no html content, just send plain text email
                $config['mailtype'] = 'text';
                $this->email->initialize($config);
                $this->email->message($email->message);    

            
            }

}




Theme © iAndrew 2016 - Forum software by © MyBB