Professional CodeIgniter

(singke) #1

Chapter 8: Last-Minute Upgrades


263


$this- > email- > from(‘[email protected]’, ‘ClaudiasKids.net’);
$this- > email- > to(‘[email protected]’);
$this- > email- > subject($subject);
$this- > email- > message($msg);
$this- > email- > send();
$this- > session- > set_flashdata(‘message’, “Test email sent”);
write_file(‘/tmp/email.log’, $subject .”|||”.$msg);
redirect(‘admin/subscribers/sendemail’,’refresh’);
}else{
$subs = $this- > MSubscribers- > getAllSubscribers();
foreach ($subs as $key = > $list){
$unsub = “ < p > < a href=’”. base_url().”welcome/unsubscribe/”
.$list[‘id’]. “’ > Unsubscribe < /a > < /p > ”;
$this- > email- > clear();
$this- > email- > from(‘[email protected]’, ‘ClaudiasKids.net’);
$this- > email- > to($list[‘email’]);
$this- > email- > bcc(‘[email protected]’);
$this- > email- > subject($subject);
$this- > email- > message($msg. $unsub);
$this- > email- > send();
}
$this- > session- > set_flashdata(‘message’, count($subs). “ emails sent”);
}
redirect(‘admin/subscribers/index’,’refresh’);
}else{
if ($this- > session- > flashdata(‘message’) == “Test email sent”){
$lastemail = read_file(‘/tmp/email.log’);
list($subj,$msg) = explode(“|||”,$lastemail);
$data[‘subject’] = $subj;
$data[‘msg’] = $msg;
}else{
$data[‘subject’] = ‘’;
$data[‘msg’] = ‘’;
}
$data[‘title’] = “Send Email”;
$data[‘main’] = ‘admin_subs_mail’;
$this- > load- > vars($data);
$this- > load- > view(‘dashboard’);
}
}

Finally, it ’ s time to update the view. You need to set it such that the values for the subject and
message fields accept the values from the controller. That ’ s easily remedied by adding a value index for
each form field ’ s array.

One last thing: It would be good to add a way to display the flash data message, so that users know if a
test e - mail was sent:


< ?php
echo $this- > tinyMce;
if ($this- > session- > flashdata(‘message’)){
echo “ < div class=’message’ > ”.$this- > session- > flashdata(‘message’).” < /div > ”;
}
Free download pdf