簡體   English   中英

解碼pdf字符串並通過codeigniter電子郵件功能發送它

[英]decoding pdf string and sending it by codeigniter email functionality

我正在使用dompdf來生成pdf,我正在使用原始字符串,將其編碼以便稍后將其保存到數據庫然后解碼它以便我可以將其作為電子郵件的附件發送,但無論如何我無法做到。 我在這里嘗試了兩個示例PHP發送帶有PDF附件的電子郵件而不創建文件? PHP從base64編碼的數據字符串中獲取pdf文件,但我無法使其正常工作。

所以這是代碼

public function generateCreditAggreement(){
        $this->load->helper('file'); 
        require_once(APPPATH.'third_party/dompdf/dompdf_config.inc.php');

            $dompdf = new Dompdf();


            $msg = $this->load->view('credit_agreement_view', '', true);
            $html = mb_convert_encoding($msg, 'HTML-ENTITIES', 'UTF-8');
            $dompdf->load_html($html);

//            $dompdf->set_paper('A4', 'Potrait');
            $paper_orientation = 'Potrait';

            $dompdf->set_paper($paper_orientation);

            // Render the HTML as PDF
            $dompdf->render();

            // Output the generated PDF to Browser
//          $dompdf->stream('document.pdf');
//          $id = "sup";
//          $dompdf->stream("$id.pdf", array("Attachment" => false));           

            $pdf_string =   $dompdf->output();

            $new_pdf = write_file('name', $pdf_string);


            $pdf_content =  base64_encode($pdf_string);
//          $this->load->model('agreement_page');
//          $pushString = $this->agreement_page->storePdfString($pdf_content);

            //Decode pdf content
            $pdf_decoded = base64_decode ($pdf_content);
            //Write data back to pdf file
            $pdf = fopen ('credit_agreement.pdf','w');
            fwrite ($pdf,$pdf_decoded);
            //close output file
            fclose ($pdf);




            // sending the pdf to email



            $this->load->library('email');
            $config['protocol'] = 'smtp';

            $config['smtp_host'] = 'ssl://smtp.gmail.com';

            $config['smtp_port']    = '465';

            $config['smtp_timeout'] = '7';

            $config['smtp_user']    = 'support@aurorax.co';

            $config['smtp_pass']    = '';

            $config['charset']    = 'utf-8';

            $config['newline']    = "\r\n";

            $config['mailtype'] = 'text'; // or html

            $config['validation'] = TRUE; // bool whether to validate email or not      

            $this->email->initialize($config);

            $this->email->from('support@aurorax.co', 'aurora exchange');
            $this->email->to('masnad@aurorax.co');
            $this->email->subject('pdf');
            $this->email->attach('myfile.pdf' , $pdf,'application/pdf');
            $this->email->message('Your pdf is here');  
//            $this->email->attach($pdf);
            $this->email->send();      

    }

現在苦苦掙扎了2天,無法讓它發揮作用。

我更改了兩行Codeigniter Email類,這樣我就可以輕松地將base64字符串作為附件發送。

https://github.com/aqueeel/CI-Base64EmailAttach

用此下載並替換您的電子郵件類。

將配置數組初始化為:

$config['_encoding'] = 'base64';
$this->load->library('email',$config);

使用mime類型調用attachmnet函數:

$this->email- >attach($base64,'attachment','report.pdf','application/pdf');.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM