如何发送电子邮件附件中归档的多个文件。
在视图文件中
<input type="file" name="attachment" id="file_1" />
<input type="file" name="attachmenttwo" id="file_2" />
<input type="file" name="attachmentthree" id="file_3" />
在我的控制器中
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|txt';
$config['max_size'] = '100000';
$config['overwrite'] = TRUE;
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->load->library('email');
$this->load->library('encrypt');
$this->upload->initialize($config);
$this->upload->do_upload('attachment');
$this->upload->do_upload('attachmenttwo');
$this->upload->do_upload('attachmenthree');
$ret = $this->upload->data();
$rettwo = $this->upload->data();
$retthree = $this->upload->data();
$pathToUploadedFile = $ret['full_path'];
$pathToUploadedFiletwo = $rettwo['full_path'];
$pathToUploadedFilethree = $retthree['full_path'];
$this->email->from('abc@gmail');
$this->email->to('[email protected]');
$this->email->subject('New query');
$this->email->message('hi');
$this->email->attach($pathToUploadedFile);
$this->email->attach($pathToUploadedFiletwo);
$this->email->attach($pathToUploadedFilethree);
$this->email->send();
这是我能够在服务器中成功上传文件但无法通过电子邮件发送附件,我在收件箱中收到了最后一个文件 3 次。
建议我如何发送邮件收件箱中的所有文件
使用此代码
首先我们需要使用名称在服务器上上传数据然后我们附加文件名然后我们创建循环然后发送电子邮件
if($this->input->post('attachment') && !empty($_FILES['userFiles']['name'])){
$filesCount = count($_FILES['userFiles']['name']);
for($i = 0; $i < $filesCount; $i++){
$_FILES['userFile']['name'] = $_FILES['userFiles']['name'][$i];
$_FILES['userFile']['type'] = $_FILES['userFiles']['type'][$i];
$_FILES['userFile']['tmp_name'] = $_FILES['userFiles']['tmp_name'][$i];
$_FILES['userFile']['error'] = $_FILES['userFiles']['error'][$i];
$_FILES['userFile']['size'] = $_FILES['userFiles']['size'][$i];
$uploadPath = './uploads/';
$config['upload_path'] = $uploadPath;
$config['allowed_types'] = 'gif|jpg|png|txt';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload('userFile')){
$fileData = $this->upload->data();
$this->load->library('email');
$this->email->from('[email protected]');
$this->email->to('[email protected]');
$this->email->subject('New query');
$this->email->message($message);
$pathToUploadedFile = $fileData['full_path'];
$this->email->attach($pathToUploadedFile);
}
}
$this->email->send();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句