PHP-Codeigniter将pdf文件作为电子邮件附件发送

我正在使用TCPDF动态生成pdf文件.通过使用TCPDF,我现在获取具有base64编码的原始文件,现在我想使用codeigniter电子邮件帮助程序功能将此原始数据作为电子邮件附件发送.

怎么办

解决方法:

花了我一段时间寻找答案,希望它对以后的任何人有帮助:

    // Get email address and base64 via ajax
    $email = $this->input->post('email');
    $base64 = $this->input->post('base64');

    $base64 = str_replace('data:application/pdf;base64,', '', $base64);
    $base64 = str_replace(' ', '+', $base64);

    $data = base64_decode($base64);

    // Locally emails do now work, so I use this to connect through my gmail account to send emails
    $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'MyEmailAddress@gmail.com',
        'smtp_pass' => 'MyEmailPassword',
        'mailtype'  => 'html', 
        'charset'   => 'iso-8859-1'
    );

    $this->load->library('email', $config);

    $this->email->set_newline("\r\n");
    $this->email->to($email);
    $this->email->from('noreply@whatever.ca', 'base64');
    $this->email->subject('base64');
    // Using the string_attach($str_file, $filename, $mime, $disposition = 'attachment')
    // function located in CodeIgniter\application\libraries\Email.php
    $this->email->string_attach($data, 'base64.pdf', 'application/pdf');

    $this->email->send();
上一篇:php-使用TCPDF将空间写入PDF文件


下一篇:php – 带特殊字符的TCPDF HTML显示空PDF文件