Post by sipherz » Thu Mar 29, 2012 4:03 pm

Hi

Whats the easiest way to add a PDF attachment to the email that customers receive when they place an order?

Thanks

New member

Posts

Joined
Thu Aug 11, 2011 4:33 pm

Post by sipherz » Thu Mar 29, 2012 5:25 pm

Seems I can use

Code: Select all

addAttachment()
in orders.php

New member

Posts

Joined
Thu Aug 11, 2011 4:33 pm

Post by sipherz » Thu Mar 29, 2012 6:52 pm

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:

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'));
The problem is that it throws an error:
PHP Warning: fopen(example_001.pdf) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied
Using the

Code: Select all

 addAttachment()
method, how do I attach a PDF created on the fly?

I've tried using the 'I' and the 'E' flag in the

Code: Select all

$pdf->output()
methods, but none seem to work

Thanks

New member

Posts

Joined
Thu Aug 11, 2011 4:33 pm

Post by sipherz » Thu Mar 29, 2012 11:18 pm

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:

Code: Select all

$mail->addAttachment(DIR_IMAGE.'/opencart/httpdocs/pdfs/example_001.pdf', md5(basename('example_001.pdf'))));
The PDF is already in the folder as a demo, but not in my email attachment

Any ideas?

New member

Posts

Joined
Thu Aug 11, 2011 4:33 pm

Post by S@nder42 » Thu May 10, 2012 3:54 am

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

Code: Select all

 $mail->addAttachment('test.php');
The file that I attachted is in the root of the shop.

Your script above containts DIR_IMAGE, you should not use that

Newbie

Posts

Joined
Thu May 10, 2012 3:51 am

Post by sipherz » Wed May 16, 2012 6:03 pm

All my PDFs are stored in /httpdocs/images/pdfs/

New member

Posts

Joined
Thu Aug 11, 2011 4:33 pm

Post by sumanaub » Tue Feb 26, 2013 8:05 am

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());
}
}
}
?>

Newbie

Posts

Joined
Tue Feb 26, 2013 7:55 am

Post by sniffertje » Wed Feb 27, 2013 5:36 am

I want to use a custom made PDF as attachment in the order confirmation. Does someone know how to do this?

New member

Posts

Joined
Fri Jan 08, 2010 10:42 pm

Post by mewolar » Sat May 10, 2014 6:44 pm

Same problem here.

Did you find a solution?

Joost

Newbie

Posts

Joined
Sat Apr 12, 2014 1:03 am

Post by sambick2 » Tue Jul 01, 2014 9:10 pm

Ok.

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");
before

Code: Select all

$mail->send();
It is working..

Newbie

Posts

Joined
Sun Oct 14, 2012 5:17 am

Post by v-v » Sun Jul 06, 2014 2:49 am

Hi, may I ask you where exactly you placed it?

I am trying it for several times and no success with sending an attachement with order confirm ...

Many thanks.

v-v
Active Member

Posts

Joined
Wed Jun 16, 2010 10:09 pm

Post by sambick2 » Mon Sep 01, 2014 4:11 am

Place it into the root dir. Its a dir where you have an index.php file. For my webhosting its a www dir.

Newbie

Posts

Joined
Sun Oct 14, 2012 5:17 am

Post by v-v » Sat Nov 29, 2014 9:10 am

So I have explored when it works - when mail is set as text, the attachement is sent. If mail is set as html, no attachement is sent :-(

Any idea?

Many thanks ...

v-v
Active Member

Posts

Joined
Wed Jun 16, 2010 10:09 pm

Post by DevJet » Mon Dec 18, 2017 7:40 am

for html mail try:

$html .= "<img src='path to your img'>;
$mail->setHtml($html);

Newbie

Posts

Joined
Mon Dec 18, 2017 7:37 am
Who is online

Users browsing this forum: No registered users and 36 guests