Professional CodeIgniter, Thomas Myer
Chapter 8: Last-Minute Upgrades
263
$this-
>
email-
>
from(`claudia@example.com', `ClaudiasKids.net');
$this-
>
email-
>
to(`myerman@gmail.com');
$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(`claudia@example.com', `ClaudiasKids.net');
$this-
>
email-
>
to($list[`email']);
$this-
>
email-
>
bcc(`claudia@example.com');
$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.
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
>
";
}
c08.indd 263
c08.indd 263
6/10/08 5:37:34 PM
6/10/08 5:37:34 PM