Welcome Guest, Not a member yet? Register   Sign In
File Attachment error in multiple reciever of email using codeigniter
#1

[eluser]sazet_rey[/eluser]
i am applying a code for email. The code is being developed in codeigniter.. Now i can select multiple reciever to whom the mail will be send, and files can be attached... i am posting my mailing code below...

Code:
function send_mass_mail()
        {
            if(!isset($_SESSION['uname'])){
                redirect(base_url().'admin.php/login');
            }
            $this->load->library('email');
            $dm=$this->input->post('send_domain');
            $em=$this->input->post('send_email');
            foreach($_FILES['a_file']['tmp_name'] as $key=>$val)
            {
                echo $_FILES['a_file']['type'][$key];
                         if($_FILES['a_file']['name'][$key]=="")
                            {
                              continue;
                            }
                         else if($_FILES['a_file']['name'][$key]!='' &&  
                                 (end(explode('.',$_FILES['a_file']['name'][$key]))=='jpg' || end(explode('.',$_FILES['a_file']['name'][$key]))=='JPG'
                                 || end(explode('.',$_FILES['a_file']['name'][$key]))=='jpeg' || end(explode('.',$_FILES['a_file']['name'][$key]))=='JPEG'
                                 || end(explode('.',$_FILES['a_file']['name'][$key]))=='pdf'
                                 ) && $_FILES['a_file']['size'][$key]< 80000000 )
                            
                                
                         {
                             $att= 'attachment/'.md5(uniqid(rand())).$_FILES['a_file']['name'][$key];
                             $att_file='./'.$att;
                             move_uploaded_file($val,$att_file);
                         }
            }
            $config['charset'] = 'utf-8';
            $config['wordwrap'] = TRUE;
            $config['mailtype'] = 'html';
            $config['protocol'] = 'sendmail';
            $this->email->initialize($config);
            $this->email->from($em, $dm);
            $this->email->subject($this->input->post('subject'));
            $msg=$this->input->post('cont');;
            $this->email->message($msg);
            $path='attachment/';
            $handle=opendir($path);
            while (($file = readdir($handle)))
                  {
                       if(strlen($file)>3)
                           $this->email->attach('./attachment/'.$file);
                  }
            closedir($handle);
            foreach($this->input->post('contact_email') as $p)
            {
                $this->email->to($p);
            }
            $this->email->send();
            $path='attachment/';
            $handle=opendir($path);
            while (($file = readdir($handle)))
                  {
                       if(strlen($file)>3)
                           unlink('./attachment/'.$file);
                  }
            closedir($handle);
            $this->load->view('mail_sent_successfully');
            //echo $this->email->print_debugger();
            
       }


now as u can see, `$this->input->post('contact_email')` is an array of posted emails resembling the reciever's email.. in html its declared as

&lt;input type="checkbox" name="contact_email[]" value="&lt;?php echo $b['contact_email'];?&gt;"/&gt;



now my problem is that suppose i have a list of for people namely

1) abhishek
2) sabuj
3) saswat
4) manas.


i am attaching some files to the mail...first i have created a folder in server named attachments where all the files for attachment will be uploaded, then they will be attached, then the email will be send and then the attachment folder will be cleared...

now the problem is when i am selecting multiple reciever, say the above 4, then the person at position 1 is getting 1 file as attached, person 2 as 2 same files as attachment, person 4 gets 4 same files attached.. actualy files being attached by the no. of times they are representing in the list...i need to solve this attachment error, mail is going as single, but attachment as multiple..

please help me solving this
#2

[eluser]Rayhan[/eluser]
$this->email->clear(true);




Theme © iAndrew 2016 - Forum software by © MyBB