多个电子邮件附件

时间:2014-08-18 22:27:32

标签: codeigniter email attachment

我想在我的电子邮件中添加四个文件。我担心这段代码不起作用,我无法测试它因为我在localhost上运行。请帮帮我。

    else
        {

            $config['upload_path'] = './att/';
            $path=$config['upload_path'];
            $config['allowed_types'] = 'doc|pdf|docx';
            $this->load->library('upload');
            $this->upload->initialize($config);

           foreach($_FILES as $fieldname => $fileObject)  //fieldname is the form field name
           {  
               if($this->upload->do_upload($fieldname))
                {
                 $return=$this->upload->data();
                 $this->email->attach($return['full_path']);
                }
                else
                {    
               $this->set_fleshdata();
               $this->session->set_flashdata('errors', 'Files must be in doc,docx, or pdf format!');
               header('Location: '.$_SERVER['HTTP_REFERER']);
                }
           }

            $message='';
            $message.='Full name: '. $this->input->post('fullname').br();
            $message.='Permanent Home Address: ' . $this->input->post('address').br();
            $message.='Email Address: ' . $this->input->post('posta').br();
            $message.='Country of Citizenship: ' . $this->input->post('country').br();
            $message.='Date of Birth: ' . $this->input->post('date').br();
            $message.='Telephone Number: ' . $this->input->post('tel').br();
            $message.='Name of Institution: ' . $this->input->post('inst').br();
            $message.='Field of Study: ' . $this->input->post('study').br();
            $message.='Degree awarded/expected: ' . $this->input->post('degree').br();
            $message.='Dates attended: ' . $this->input->post('dates1').br();
            $message.='Dates attended: ' . $this->input->post('dates2').br();
            $message.='Employment: ' . $this->input->post('employment').br();
            $message.='Language Skills: ' . $this->input->post('language').br();
            $message.='Statement: ' . $this->input->post('statement').br();

            $this->email->to($this->config->item('system_email'));
            $this->email->subject(lang('mail_title').$this->config->item('base_url'));
            $this->email->from($this->input->post('email'));
            $this->email->message($message);
            $this->email->send();
            unlink($return['full_path']);
        }
    }

我的问题是这项工作是$ this-> email-> attach($ return [' full_path']);在foreach循环中,得到我的4个邮件附件的结果,我可以把它放在foreach循环外面。我使用unlink函数来删除文件,它是否适用于附件???

$this->email->attach($return['full_path']);
$this->email->from($this->input->post('email'));
$this->email->message($message);
$this->email->send();
unlink($return['full_path']);

0 个答案:

没有答案