Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Codeigniter中发送电子邮件时如何下载和附加文件?_Php_Codeigniter - Fatal编程技术网

Php 在Codeigniter中发送电子邮件时如何下载和附加文件?

Php 在Codeigniter中发送电子邮件时如何下载和附加文件?,php,codeigniter,Php,Codeigniter,-我想点击下载按钮,下载此账单作为pdf格式,同时我想将此pdf附在电子邮件中 我使用这个代码- public function details_pdf($id) { $this->load->model('user_model'); $this->load->helper('download'); $data['invoice_detls'] = $this->user_model->front_get_invoice_detail

-我想点击下载按钮,下载此账单作为pdf格式,同时我想将此pdf附在电子邮件中

我使用这个代码-

public function details_pdf($id) {
    $this->load->model('user_model');
    $this->load->helper('download');

    $data['invoice_detls'] = $this->user_model->front_get_invoice_details(['front_orders_id'=>$id]);
    $data['items'] = $this->user_model->front_get_ordered_items(['front_dish_invoice_id' => $id]);

    //$data['abstract_message'] = $this->user_model->get_abstract_message(['abstract_id' => $id]);
    //$data['user_details'] = $this->user_model->get_user(['id' => $data['abstract_message'][0]['user_id']]);

    //$data['user_details_member'] = $this->user_model->get_profile_details(['members.userid' => $data['abstract_message'][0]['user_id']]);
    //print_r($data['user_details']);die();

    $customer_name =  $data['invoice_detls'][0]['customer_name'];
    $customer_phone =  $data['invoice_detls'][0]['customer_phone'];

    //load the view and saved it into $html variable
    $html = $this->load->view('front_billing_view', $data, true);
    $time = time();


    //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("\r\n");
            $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-----------------------*/ 


}
此代码仅下载pdf,但我无法将下载文件作为电子邮件发送给单击“下载”按钮的用户,因为此文件存储在桌面而不是项目文件夹中。如何解决此问题?

方法需要完整的路径/名称,例如,`/home/user/file.pdf'-

在使用下载选项生成pdf文档之前,您可以在本地生成pdf,然后使用下载选项生成pdf

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

// save it 
$tmpPdfFile = '/home/user/file.pdf'; // change this acording to your configuration
$mpdf->Output($tmpPdfFile,'F');

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


// attach file to mail
 $this->email->attach($tmpPdfFile);
 $this->email->send();

// delete $tmpPdfFile after email send if you don't need it
unlink($tmpPdfFile);

这:
$pdfFilePath=“$customer\u name.''.$customer\u phone.''.$time.pdf”看起来很奇怪。它会产生一个类似这样的字符串:
thename.'''.''.'.''.thephone.''.'.12345.pdf
。这看起来不是一个好的文件名。如果你想重复使用生成的PDF,请将其存储在服务器上的临时文件夹中,然后使用该文件夹下载并添加到电子邮件中。如何操作?请查看手册以了解你正在使用的PDF库。这是来自mPDF文档页面如何将此特定PDF保存在我的服务器文件夹中?请参阅我的回复,在
//保存它之后
注释$tmpPdfFile='/download/'.$pdfFilePath;//根据您的配置$mpdf->Output($tmpPdfFile,'F');-我添加了这个代码。“$PdfilePath”这是我的原始文件名。Downloads是我要保存的文件夹。现在它工作了吗?我建议$tmpPdfFile是一个完整的路径,比如c:/temp/my_pdf_file.pdfI用于$tmpPdfFile。但我得到空值。我创建下载文件夹来保存pdf文件。