Welcome Guest, Not a member yet? Register   Sign In
attach multiple file in email
#1

I would like attach the files uploaded from my form to email. The files are correctly uploaded in the folder but the email has only 1 attachment. How can i solve this problem? Thanks.

My code:
PHP Code:
               $config['upload_path'         './media/images/uploads/';
 
               $config['allowed_types'       'gif|jpg|png|pdf';
 
               $config['max_size'            100;
 
               $config['max_width'           1024;
 
               $config['max_height'          768;

                
$files $_FILES;
                
$count count($_FILES['userfile']['name']);
                
                for(
$i 0$i $count$i++) {
                 
  $_FILES['userfile']['name'    $files['userfile']['name'][$i];
                 
  $_FILES['userfile']['type'    $files['userfile']['type'][$i];
                 
  $_FILES['userfile']['tmp_name'] = $files['userfile']['tmp_name'][$i];
                 
  $_FILES['userfile']['error'   $files['userfile']['error'][$i];
                 
  $_FILES['userfile']['size'    $files['userfile']['size'][$i]; 
 
  
                $this
->load->library('upload'$config);

 
               if ( ! $this->upload->do_upload('userfile'))
 
               {
 
                     $this->form_validation->set_error_delimiters('<p class="error">''</p>');
 
                     $error = array('error' => $this->upload->display_errors());
 
               }
 
               else
                
{
 
                    $upload_data $this->upload->data();
 
               }
 
               
//attach email
$this->email->attach($upload_data['full_path']); 
Reply
#2

You can attach as many files as you like, just cascade them.

$this->email->attach($full_path_and_name);
$this->email->attach($full_path_and_name);

In your case if your using the FILES array you would need to attach them
inside of a for loop, getting the file path and name into a string variable.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(09-14-2017, 08:47 AM)InsiteFX Wrote: You can attach as many files as you like, just cascade them.

$this->email->attach($full_path_and_name);
$this->email->attach($full_path_and_name);

In your case if your using the FILES array you would need to attach them
inside of a for loop, getting the file path and name into a string variable.

Thanks for your answer and for have help me.

I have solved adding
PHP Code:
$this->email->attach($upload_data['full_path']); 
  inside my loop for, under the variable 
PHP Code:
$upload_data $this->upload->data(); 
Now i receive all attachments.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB