0

I want to send a mail and attach a file which I get to click the download button of pdf?

//this the the PDF filename that user will get to download
$pdfFilePath = "$customer_name.'_'.$customer_phone.'_'.$time.pdf";

$this->user_model->update_order(['front_orders_id' => $id],['bill_pdf'=>$pdfFilePath]);

//load mPDF library
$this->load->library('m_pdf');

//generate the PDF from the given html
$this->m_pdf->pdf->WriteHTML($html);

//download it.
$this->m_pdf->pdf->Output($pdfFilePath, "D");

/*--------------------Mail function Start-----------------------*/
    $order_fetch = $this->user_model->front_get_invoice_details(['front_orders_id' => $id]);

    $email = $order_fetch[0]['customer_email'];
    $pdf_name = $order_fetch[0]['bill_pdf'];
        $config = Array(
           'protocol' => 'smtp',
           'smtp_host' => 'ssl://smtp.googlemail.com',
           'smtp_port' => 465,
           'smtp_user' => 'noreply@wsdev.in',
           'smtp_pass' => '%KidFlash!2#4%',
           'mailtype' => 'text/html',
           'charset' => 'iso-8859-1',
           'charset' => 'utf-8'
        );
        $this->load->library('email');
        $this->email->set_mailtype("html");
        $this->email->set_newline("\r\n");
        $from_email = 'noreply@wsdev.in';
        $this->email->from($from_email);
        $this->email->to($email);
        $this->email->subject('Order Delivered');
        $this->email->message('Your Order Successfully Delivered.');                       
        $this->email->attach($pdfFilePath);
        $this->email->send();

/*--------------------Mail Function End-----------------------*/ 

enter image description here

-This is my code. When I hit the download button, I want to download this page as a pdf and send as an attachment.

1 Answers1

0
$config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => 'abc@gmail.com', 
      'smtp_pass' => 'passwrd', 
      'mailtype' => 'html',
      'charset' => 'iso-8859-1',
      'wordwrap' => TRUE
    );


          $this->load->library('email', $config);
          $this->email->set_newline("\r\n");
          $this->email->from('abc@gmail.com');
          $this->email->to($email);
          $this->email->subject($subject);
          $this->email->message($message);
            $this->email->attach('C:\Users\xyz\Desktop\images\abc.pdf');
          if($this->email->send())
         {
          echo 'Email send.';
         }
         else
        {
         show_error($this->email->print_debugger());
        }

$this->email->attach('C:\Users\xyz\Desktop\images\abc.png'); give extact the file location

This code only reference.Check the code and change in your way

Also check $pdfFilePath gets correct value.In $pdfFilePath variable give extact file location of document like C:\Users\xyz\Desktop\images\abc.pdf

annz
  • 309
  • 1
  • 18