[eluser]RMinor[/eluser]
Now that I think about how I have my code set up I am not sure that it will work. Take a look below and see what I mean.
Controller (important parts of it)
Code:
// Retrieve all persons that need to be sent emails
$persons = $this->Person_model->getPersonsByCasting($id);
foreach ($persons as $recipient) {
// Make sure the person has not received an email already
if ($recipient['person_email_sent'] == 'No') {
// Determine which email to send to each person
switch ($recipient['person_status']) {
// Send approved email
case 'approved':
$data['emails'] = $this->Email_model->sendApprovedEmail($recipient['person_email']);
break;
// Send deleted email
case 'deleted':
$data['emails'] = $this->Email_model->sendDeletedEmail($recipient['person_email']);
break;
// Send on file email
case 'file':
$data['emails'] = $this->Email_model->sendFileEmail($recipient['person_email']);
break;
// Send hold email
case 'hold':
// Generate a random password for the person to log in with
$password = $this->Person_model->holdPerson($recipient['person_id']);
$data['emails'] = $this->Email_model->sendHoldEmail($recipient['person_email'], $password);
break;
}
}
// Load the required view
$this->load->view('submission-emails_view', $data);
Model (each method looks the same)
Code:
/**
* Method to send email to deleted persons
* @param string $email
*/
public function sendDeletedEmail($email)
{
$result = array();
$body = $this->_retrieveEmailBody('deleted');
$this->email->from($this->_from_address, $this->_from_name);
$this->email->to($email);
$this->email->subject($this->_retrieveEmailBody('deleted'));
$this->email->message($body);
$s = 0;
$f = 0;
if ($this->email->send()) {
$result = array(
'sent' => array($s => $email)
);
$s++;
} else {
$result = array(
'failed' => array($f => $email)
);
$f++;
}
return $result;
}
Then in my view I wanted to display a list of all sent and all failed emails. I am not sure if my current setup will accomplish this.