Welcome Guest, Not a member yet? Register   Sign In
Bug width Email attach
#1
Exclamation 

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
Reply
#2

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/li...email.html
Reply




Theme © iAndrew 2016 - Forum software by © MyBB