Professional CodeIgniter, Thomas Myer
Chapter 8: Last-Minute Upgrades
260
Rewriting the sendemail() Function
Now it ' s time to rewrite the
sendemail()
function you wrote above. You have three possible outcomes,
in order of simplicity:
There are no POST data
-- If so, simply send the user to the admin_subs_mail view, so she can
compose a message.
There are POST data, and the test flag is TRUE
-- In this case, simply send the composed
message to the test recipient (in your case, Claudia).
There are POST data, and the test flag is FALSE
-- In this case, extract the subscribers from the
database using the
getAllSubscribers()
function of MSubscribers, and then send the
message to those subscribers.
The way this three - part logic tree manifests itself is as an if-else condition, with the first if branch (POST
data exist) having its own if - else branch (is this a test message?) embedded in it.
It ' s almost as complicated talking about it as seeing it in action, so without further ado, here ' s the code.
Figure 8 - 9
c08.indd 260
c08.indd 260
6/10/08 5:37:33 PM
6/10/08 5:37:33 PM