CodeIgniter Forums
Bug width Email attach - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forum-6.html)
+--- Forum: Issues (https://forum.codeigniter.com/forum-19.html)
+--- Thread: Bug width Email attach (/thread-61769.html)



Bug width Email attach - motoroller - 05-15-2015

I have a simple email function

PHP Code:
function sendLetter($data) {



 $CI =& get_instance();


 $CI->load->library('email');


 $config = array (


 
       'protocol'  => 'smtp',


 
       'smtp_host' => SMTP_HOST,


 
       'smtp_port' => SMTP_PORT,


 
 'smtp_user' => SMTP_USER


 
       'smtp_pass' => SMTP_PASS,


 
       'mailtype'  => 'html',


 
       'charset'   => 'UTF-8',


 
 'newline'   => '\r\n'    


    
);

 if(isset($data['attach']))
  $CI->email->attach($data['attach']); 
 
$CI
->email->initialize($config); 
 $CI
->email->from('[email protected]''Peter');
 $CI->email->message($CI->twig->render('mail_templates/body'$data));
 $CI->email->to($data['to']);
 $CI->email->subject($data['title']);
 return $CI->email->send() ? 'ok' 'error';
}

Then I call function two times

sendLetter 
(

    array (
    'title' => 'First Letter',
    'to' => '[email protected]',
    'file' => 'mail_templates/invoice.html',
    'attach' => $file,
   )
  ); 
PHP Code:
    array 
PHP Code:
    'title' => Second Letter', 
PHP Code:
    'to' => '[email protected]'
PHP Code:
    'file' => 'mail_templates/invoice.html',
    'attach' => $file
PHP Code:
   
PHP Code:
  ); 
PHP Code:
     
PHP Code:
   
PHP Code:
sendLetter (

    array (
    'title' => 'First Letter',
    'to' => '[email protected]',
    'file' => 'mail_templates/invoice.html',
    'attach' => $file,
   )
  ); 

The problem is second receiver has two (double attaches ) in his letter


RE: Bug width Email attach - Wouter60 - 05-15-2015

The $CI->email->send() method clears all settings, except the attachment(s). If you want to clear that too, use $CI->email->clear(TRUE).
It is described in the documentation: http://www.codeigniter.com/userguide3/libraries/email.html