首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用协作器在邮件功能中附加pdf文件?

如何使用协作器在邮件功能中附加pdf文件?
EN

Stack Overflow用户
提问于 2018-06-09 20:33:46
回答 1查看 542关注 0票数 0

如何使用CodeIgniter在邮件中附加PDF文件?

我收到了邮件。但我没发现里面有任何附件。

我使用了以下代码:

代码语言:javascript
复制
public function sendmail()
{
    $this->load->library('email');

    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100000';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';

    $this->load->library('upload', $config);
    $this->upload->do_upload('attachment');
    $upload_data = $this->upload->data();

    $this->email->set_newline("\r\n");
    $this->email->set_crlf("\r\n");
    $this->email->from('sskwebtech@gmail.com');
    $this->email->to($this->input->post('to'));
    $this->email->subject($this->input->post('subject'));
    $this->email->message($this->input->post('message'));


    if ($this->email->send()) {
        echo "Mail Send";
        return true;
    } else {
        show_error($this->email->print_debugger());
    }
}
EN

回答 1

Stack Overflow用户

发布于 2018-06-10 14:14:56

100%工作正确的代码,冗长但有用。不要浪费时间,尽情享受吧!

代码语言:javascript
复制
//View

<?php echo form_open_multipart('Jobs_portal/job_apply')?>
<input type="file" 
name="userfile" accept="application/msword,application/pdf" 
required="">
<button type="submit">Submit</button>
</form>
//end view


//Controller <Jobs_portal>

public function job_apply()
{

            $q=$this->file_upload(); //calling function file_upload

            if ($q) {
            $file_attribute=$this->upload->data();
            $file_name=$file_attribute['file_name'];
            $file_path=$file_attribute['file_path'];

            //calling function attachment_mail to send pdf
            $this->attachment_mail($file_path,$file_name);
            }
 }



public function file_upload()
{
            $config['upload_path']          = './uploads/';
            $config['allowed_types']        = 'doc|pdf';
            $config['max_size']             = 9000;
            $this->load->library('upload', $config);

            if ( ! $this->upload->do_upload('userfile'))
            {
                $this->upload->display_errors();
                echo "Sorry! Apply again. Check Your Resume Format";
                return false;
            }
            else
            {
                echo "i'll reply you after check your Resume. Thanks!";
                return true;    
            }
   } 

 public function attachment_mail($file_path,$file_name)
 {
            $this->load->library('email');   
            $this->load->helper('path');
            $this->email->from('No-Reply@domain.com', 'Resume Receive');
            $this->email->to('reciever@gmail.com'); 
            $this->email->subject('Apply for Job ');
            $this->email->message('Sir I have attached my Resume for Job'); 

            $this->email->attach($file_path.file_$name);
            $this->email->send();
            echo $this->email->print_debugger();
}

//end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50774357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档