Send email to create and join PDF in CodeIgniter

The output email address is sent, but does not come to my letter. I added the dompdf library. When I deleted the code that the PDF creates, then an email was sent.

My code is:

<?php
$this->load->library('dompdf_gen');
$this->dompdf->load_html($body);
$this->dompdf->render();
$output = $this->dompdf->output(APPPATH . 'Brochure.pdf', 'F');
$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());
    }
+4
source share
2 answers

You must save the attachment as a file, so use file_put_contentsto save the PDF to a file. Set permission 777 to the public:

$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
source

Use this library to convert html to pdf, which I changed for CI3. https://github.com/shyamshingadiya/HTML2PDF-CI3

Please check the solution below

//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();

, .

+1

Source: https://habr.com/ru/post/1680052/


All Articles