I am using TCPDF to create a basic PDF when an order is sent to the customer and add it as an attachment.
I have:
The problem is that it throws an error:
method, how do I attach a PDF created on the fly?
I've tried using the 'I' and the 'E' flag in the methods, but none seem to work
Thanks
I have:
Code: Select all
require_once(DIR_SYSTEM.'library/tcpdf/tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 001');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
//$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusans', '', 14, '', true);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();
// Set some content to print
$html = <<<EOD
<h1>Thanks for your order. Please visit the factory</h1>
EOD;
// Print text using writeHTMLCell()
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
$mail->addAttachment(DIR_IMAGE.$pdf->Output('example_001.pdf', 'F'));
Using thePHP Warning: fopen(example_001.pdf) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied
Code: Select all
addAttachment()
I've tried using the 'I' and the 'E' flag in the
Code: Select all
$pdf->output()
Thanks
Ok, so I can now send an email and get no error, the problem is the PDF isn't being attached.
I have changed the code to the following:
The PDF is already in the folder as a demo, but not in my email attachment
Any ideas?
I have changed the code to the following:
Code: Select all
$mail->addAttachment(DIR_IMAGE.'/opencart/httpdocs/pdfs/example_001.pdf', md5(basename('example_001.pdf'))));
Any ideas?
Hey i'am trying the same and creating a pdf on the fly does not work for me.
I can attach a file to the mail by using
The file that I attachted is in the root of the shop.
Your script above containts DIR_IMAGE, you should not use that
I can attach a file to the mail by using
Code: Select all
$mail->addAttachment('test.php');
Your script above containts DIR_IMAGE, you should not use that
i face same problem but how can i get the solution plz plz
<?php
class ControllerInformationcontactsupport extends Controller {
public function index() {
$this->language->load('information/contact');
$this->data['action'] = $this->url->link('information/contact-support');
$upload_folder = HTTP_IMAGE;
if (($this->request->server['REQUEST_METHOD'] == 'POST')){
$name_of_uploaded_file = basename($_FILES['uploaded_file']['name']);
$type_of_uploaded_file = substr($name_of_uploaded_file,
strrpos($name_of_uploaded_file, '.') + 1);
$size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;
$name_of_uploaded_file='add.png';
$path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
//echo $path_of_uploaded_file;
$tmp_path = $_FILES["uploaded_file"]["tmp_name"];
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->request->post['email']);
$mail->setSender($this->request->post['name']);
$mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
$mail->setText($this->request->post['message']);
$mail->addAttachment($name_of_uploaded_file);
$mail->send();
$this->redirect($this->url->link('information/contact/success'));
}
else{
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/contact-support.tpl')) { //if file exists in your current template folder
$this->template = $this->config->get('config_template') . '/template/information/contact-support.tpl'; //get it
} else {
$this->template = 'default/template/information/contact-support.tpl'; //or get the file from the default folder
}
//Required. The children files for the page.
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
}
}
?>
<?php
class ControllerInformationcontactsupport extends Controller {
public function index() {
$this->language->load('information/contact');
$this->data['action'] = $this->url->link('information/contact-support');
$upload_folder = HTTP_IMAGE;
if (($this->request->server['REQUEST_METHOD'] == 'POST')){
$name_of_uploaded_file = basename($_FILES['uploaded_file']['name']);
$type_of_uploaded_file = substr($name_of_uploaded_file,
strrpos($name_of_uploaded_file, '.') + 1);
$size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;
$name_of_uploaded_file='add.png';
$path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
//echo $path_of_uploaded_file;
$tmp_path = $_FILES["uploaded_file"]["tmp_name"];
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->request->post['email']);
$mail->setSender($this->request->post['name']);
$mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
$mail->setText($this->request->post['message']);
$mail->addAttachment($name_of_uploaded_file);
$mail->send();
$this->redirect($this->url->link('information/contact/success'));
}
else{
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/contact-support.tpl')) { //if file exists in your current template folder
$this->template = $this->config->get('config_template') . '/template/information/contact-support.tpl'; //get it
} else {
$this->template = 'default/template/information/contact-support.tpl'; //or get the file from the default folder
}
//Required. The children files for the page.
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
}
}
?>
I want to use a custom made PDF as attachment in the order confirmation. Does someone know how to do this?
Ok.
I gave my Obchodni_Podminky.pdf to the root directory (www). In catalog/model/checkout/order.php I added
before
It is working..
I gave my Obchodni_Podminky.pdf to the root directory (www). In catalog/model/checkout/order.php I added
Code: Select all
$mail->AddAttachment("Obchodni_Podminky.pdf", "Obchodni_Podminky.pdf");
Code: Select all
$mail->send();
Who is online
Users browsing this forum: No registered users and 95 guests