繁体   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