Welcome Guest, Not a member yet? Register   Sign In
Sending Emails from Database
#1

[eluser]RMinor[/eluser]
In my application I will need to occasionally send emails based on certain criteria from a database. What I want to do is store the sent emails in an array and the failed emails in an array and then display them on the view when the script is done running. What I have so far is below, but I am not sure if this will work for me. Can anyone see anything I am doing wrong or could be doing better?

Code:
public function sendApproveEmail($email)
{
    $result = array();
    $body = $this->_retrieveEmailBody('approved');
    $this->email->from($this->_from_address, $this->_from_name);
    $this->email->to($email);  
    $this->email->subject('');
    $this->email->message($body);
    if ($this->email->send()) {
        $result = array(
            'sent' => array($email)
        );
    } else {
        $result = array(
            'failed' => array($email)
        );
    }
    return $result;
}

Then in the view would I access this array by:
Code:
foreach ($result as $email) {
    foreach ($sent as $successful) {
        // Do something
    }
    foreach ($failed as $failure) {
        // Do something
    }
}


Messages In This Thread
Sending Emails from Database - by El Forum - 09-04-2012, 08:24 AM
Sending Emails from Database - by El Forum - 09-04-2012, 08:35 AM
Sending Emails from Database - by El Forum - 09-04-2012, 08:42 AM
Sending Emails from Database - by El Forum - 09-04-2012, 09:14 AM
Sending Emails from Database - by El Forum - 09-04-2012, 09:50 AM
Sending Emails from Database - by El Forum - 09-04-2012, 09:54 AM
Sending Emails from Database - by El Forum - 09-04-2012, 10:19 AM
Sending Emails from Database - by El Forum - 09-04-2012, 11:35 AM
Sending Emails from Database - by El Forum - 09-04-2012, 11:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB