dongpeng0127 2018-08-01 07:18
浏览 86

在Codeigniter中发送邮件时如何上传文件?

I want to send a mail and attach a file which I get to click the download button of pdf?

//this the the PDF filename that user will get to download
$pdfFilePath = "$customer_name.'_'.$customer_phone.'_'.$time.pdf";

$this->user_model->update_order(['front_orders_id' => $id],['bill_pdf'=>$pdfFilePath]);

//load mPDF library
$this->load->library('m_pdf');

//generate the PDF from the given html
$this->m_pdf->pdf->WriteHTML($html);

//download it.
$this->m_pdf->pdf->Output($pdfFilePath, "D");

/*--------------------Mail function Start-----------------------*/
    $order_fetch = $this->user_model->front_get_invoice_details(['front_orders_id' => $id]);

    $email = $order_fetch[0]['customer_email'];
    $pdf_name = $order_fetch[0]['bill_pdf'];
        $config = Array(
           'protocol' => 'smtp',
           'smtp_host' => 'ssl://smtp.googlemail.com',
           'smtp_port' => 465,
           'smtp_user' => 'noreply@wsdev.in',
           'smtp_pass' => '%KidFlash!2#4%',
           'mailtype' => 'text/html',
           'charset' => 'iso-8859-1',
           'charset' => 'utf-8'
        );
        $this->load->library('email');
        $this->email->set_mailtype("html");
        $this->email->set_newline("
");
        $from_email = 'noreply@wsdev.in';
        $this->email->from($from_email);
        $this->email->to($email);
        $this->email->subject('Order Delivered');
        $this->email->message('Your Order Successfully Delivered.');                       
        $this->email->attach($pdfFilePath);
        $this->email->send();

/*--------------------Mail Function End-----------------------*/ 

enter image description here

-This is my code. When I hit the download button, I want to download this page as a pdf and send as an attachment.

  • 写回答

1条回答 默认 最新

  • doumin1897 2018-08-01 08:57
    关注
    $config = Array(
          'protocol' => 'smtp',
          'smtp_host' => 'ssl://smtp.googlemail.com',
          'smtp_port' => 465,
          'smtp_user' => 'abc@gmail.com', 
          'smtp_pass' => 'passwrd', 
          'mailtype' => 'html',
          'charset' => 'iso-8859-1',
          'wordwrap' => TRUE
        );
    
    
              $this->load->library('email', $config);
              $this->email->set_newline("
    ");
              $this->email->from('abc@gmail.com');
              $this->email->to($email);
              $this->email->subject($subject);
              $this->email->message($message);
                $this->email->attach('C:\Users\xyz\Desktop\images\abc.pdf');
              if($this->email->send())
             {
              echo 'Email send.';
             }
             else
            {
             show_error($this->email->print_debugger());
            }
    

    $this->email->attach('C:\Users\xyz\Desktop\images\abc.png'); give extact the file location

    This code only reference.Check the code and change in your way

    Also check $pdfFilePath gets correct value.In $pdfFilePath variable give extact file location of document like C:\Users\xyz\Desktop\images\abc.pdf

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向