通过dompdf用codeigniter生成的pdf电子邮件

从Codeigniter中的html视图生成的PDF,现在我想将其发送到我的电子邮件,但是我遇到的麻烦是它显示$pdf中有一个字符串,但是在发送时却为空 我的电子邮件。 这是整个Codeigniter函数。

public function generatePDF()
{
    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);
    $paper_orientation = 'Potrait';
    $dompdf->set_paper($paper_orientation);

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

    // 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']    ="\
\
";
    $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($pdf);
    $this->email->message('Hello!');  

    $this->email->send();
}

首先保存,然后附加绝对路径
@ManinderpreetSingh那基本上是保存到我不想要的计算机上,我想直接将其发送到我的电子邮件中,或者稍后将其保存到mysql数据库中
更改您的这一行$ this-> email-> attach($ pdf);到$ this-> email-> string_attach($ pdf,myfile.pdf,application / pdf);
@ManinderpreetSingh我做到了,但出现错误致命错误:在C:\ Apache24 \ htdocs \中调用未定义的方法CI_Email :: string_attach()
@ManinderpreetSingh您阅读了我之前的评论吗?
抱歉,实际上此功能已删除,我打开了旧版本文档..请尝试使用$this->email->attach(myfile.pdf , $yourString,applicationpdf);
成功发送电子邮件后,您可以取消链接已保存的文件。
@Tpojka我真的不想将其保存到计算机或任何地方,所以这是一种将其保存到mysql数据库然后发送电子邮件的方法吗?我必须要找到一种方法,但是找不到
@ManinderpreetSingh我看到了$ pdf,它有一个原始字符串,如果有任何方法可以转换它,那就太好了。
试试这个stackoverflow.com/questions/17022101/
但这是生成的字符串是base64吗?
另外,在这些答案中找到有用的东西。

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注