title: Send a message in codeigniter
body: <p>I have a strange behaviour of a mail function with CodeIgniter that I try to explain but cannot figure out or reason for it.</p>
  
  <p>My function is like </p>
  
  <pre><code>function _send_email($type, $email, &amp;$data)
      {
          //original
          $this-&gt;load-&gt;library('email');
          $this-&gt;email-&gt;from($this-&gt;config-&gt;item('webmaster_email', 'tank_auth'), $this-&gt;config-&gt;item('website_name', 'tank_auth'));
          $this-&gt;email-&gt;reply_to($this-&gt;config-&gt;item('webmaster_email', 'tank_auth'), $this-&gt;config-&gt;item('website_name', 'tank_auth'));
          $this-&gt;email-&gt;to($email);
          $this-&gt;email-&gt;subject("Test Message");
          $this-&gt;email-&gt;message($this-&gt;load-&gt;view('email/'.$type.'-html', $data, TRUE));
          $this-&gt;email-&gt;set_alt_message($this-&gt;load-&gt;view('email/'.$type.'-txt', $data, TRUE));
          $this-&gt;email-&gt;send();
      }
  </code></pre>
  
  <p>This is basically inspired from Tank Auth library</p>
  
  <h2>Case where the function works fine</h2>
  
  <p>When I use this function inside a method like below the mail is sent :</p>
  
  <pre><code>function comment($postid=0){
      $poster = $this-&gt;Post-&gt;getPoster($postid); # Gets the Post author records
      $notifythisuser = $poster[0]['email']; # Gets the Post author's email
      $datacode = array('posttitle' =&gt; $this-&gt;input-&gt;post('posttitle',true),
                      'posttext' =&gt; $this-&gt;input-&gt;post('posttext',true)
                      );
      $this-&gt;_send_email('commentadded', $notifythisuser, $datacode);
      $this-&gt;post-&gt;comment();
  }
  </code></pre>
  
  <h2>Case where the function dos not work</h2>
  
  <p>Now, it is more reasonable to notify the user after the comment being sent</p>
  
  <p>so the function would be </p>
  
  <pre><code>function comment($postid=0){
      $poster = $this-&gt;Post-&gt;getPoster($postid); # Gets the Post author records
      $notifythisuser = $poster[0]['email']; # Gets the Post author's email
      $datacode = array('posttitle' =&gt; $this-&gt;input-&gt;post('posttitle',true),
                      'posttext' =&gt; $this-&gt;input-&gt;post('posttext',true)
                      );
  
      if ($this-&gt;input-&gt;post('posttitle') ){
           $this-&gt;post-&gt;comment();
           $this-&gt;_send_email('commentadded', $notifythisuser, $datacode);
           }
  }
  </code></pre>
  
  <p>Nothing  complicated I just rearranged the code so that the notification is sent after the comment is posted, the <code>comment()</code> function is very basic it is just a function that do an <code>insert</code> in a table of comment  </p>
  
  <p>I tried to debug the mail function, no errors sent, no log generated, something is wrong but I cant tell what</p>
  
  <p>any idea ?</p>
  
  <p>Thanks</p>