title: Codeigniter make sending email DRY using library or helper?
body: <p>I'm trying to get my mind around when to use custom libraries vs custom helpers vs just regular old controllers in Codeigniter. As I understand it, a custom helper should be more like small functions to accomplish simple repetitive tasks, where as a library can be a full-fledged class. </p>
  
  <p>As an example, I want to use the native email class in CI, but I'm thinking I will be using this in a variety of different controllers and want it to be as "DRY" as possible. Would it make sense to abstract the code to send an email into a helper or a library? or should I just repeat it in the needed controllers? I also have a base controller. Maybe I should place the code there? It would be used often enough to be repetitive, but it's not like every controller is using it.</p>
  
  <p>Per the documentation, the repetitive code I would be looking to abstract would be similar to the following:</p>
  
  <p>This is my code below</p>
  
  <pre><code>$this-&gt;load-&gt;library('email');
  
  $this-&gt;email-&gt;from('your@example.com', 'Your Name');
  $this-&gt;email-&gt;to('someone@example.com');
  $this-&gt;email-&gt;cc('another@another-example.com');
  $this-&gt;email-&gt;bcc('them@their-example.com');
  
  $this-&gt;email-&gt;subject('Email Test');
  $this-&gt;email-&gt;message('Testing the email class.');
  
  $this-&gt;email-&gt;send();
  </code></pre>
  
  <p>I would be using email templates and passing a <code>$data</code> array to the template.</p>