发送电子邮件以在CodeIgniter中创建和附加PDF

时间:2017-06-25 05:26:04

标签: codeigniter

输出电子邮件已发送但未到达我的电子邮件。我添加了dompdf库。当我删除创建pdf的代码时,就发送了邮件。

我的代码:

Response#headers

2 个答案:

答案 0 :(得分:1)

您必须将附件另存为文件,因此请使用file_put_contents将pdf保存到文件中。将 777 的权限设置为可供公众访问:

$this->load->library('dompdf_gen');
$this->dompdf->load_html($body);
$this->dompdf->render();       
$output = $dompdf->output();
file_put_contents(APPPATH.'Brochure.pdf', $output);
chmod(APPPATH.'Brochure.pdf', 777);

$email=$this->input->post('email');
$subject="some text";
$message=$body;
$this->sendEmail($email,$subject,$message);
$config = Array(
  'mailtype' => 'html'   );


$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('ul@ul.com');
$this->email->to($email);
$this->email->subject($subject);
$this->email->message($message);
$this->email->attach(APPPATH.'Brochure.pdf');
if($this->email->send())
{
  echo 'Email send.';
}
else
{
 show_error($this->email->print_debugger());
}

答案 1 :(得分:1)

使用此库将html转换为我为CI3修改过的pdf。 https://github.com/shyamshingadiya/HTML2PDF-CI3

请检查下面提到的解决方案

//Load the library
$this->load->library('html2pdf');

//Set folder to save PDF to
$this->html2pdf->folder('./uploads/pdfs/');

//Set the filename to save/download as
$this->html2pdf->filename('new.pdf');

//Set the paper defaults
$this->html2pdf->paper('a4', 'portrait');

用于在电子邮件中发送此特定文件。

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

$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com'); 

$this->email->subject('Email PDF Test');
$this->email->message('Testing the email a freshly created PDF');   

$this->email->attach($path_to_pdf_file);

$this->email->send();

如果不起作用,请告诉我。