nakiodev Posted August 22, 2013 Share Posted August 22, 2013 Hi, have already managed to attach a pdf file to the registration confirmation email with the following code: email to verify (free module for customers to receive a confirmation link) I modified if (!Mail::Send((int)$cookie->id_lang, 'emailverify', Mail::l('Welcome!', (int)$cookie->id_lang), array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => Tools::getValue('passwd'), '{actlink}' => $actlink), $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL, dirname(__FILE__).'/mails/') ) with $file = _PS_ROOT_DIR_ . '/terms_of_use.pdf'; // File name with no spaces no accents !!! $fileAttachment['content'] = file_get_contents($file); $fileAttachment['name'] = 'Terms Of Use.pdf'; // Name of attachement (no accents !!!) $fileAttachment['mime'] = 'application/pdf'; // Mime type of attachement if (!Mail::Send((int)$cookie->id_lang, 'emailverify', Mail::l('Welcome!', (int)$cookie->id_lang), array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => Tools::getValue('passwd'), '{actlink}' => $actlink), $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment, NULL, dirname(__FILE__).'/mails/') ) Let me know if you have ideas on how to attach the same pdf file to the order confirmation email, suggestions? thanks and sorry for the bad English Link to comment Share on other sites More sharing options...
nakiodev Posted August 22, 2013 Author Share Posted August 22, 2013 up Link to comment Share on other sites More sharing options...
nakiodev Posted August 22, 2013 Author Share Posted August 22, 2013 Solved, I added to the file mail.php (path yoursite \ classes \ mail.php) at line 270 or so, before the comment / * send email * /, this code: if ($template == 'it/order_conf') $file = _PS_ROOT_DIR_ . '/file_da_allegare.pdf'; $message->attach(new Swift_Message_Attachment(file_get_contents($file), 'file_da_allegare.pdf', 'application/pdf')); Link to comment Share on other sites More sharing options...
sbgranada Posted November 22, 2013 Share Posted November 22, 2013 thank you so much I was looking for that for a week and it works perfectly Link to comment Share on other sites More sharing options...
kmorgen Posted January 13, 2014 Share Posted January 13, 2014 I tried this and it works - however it seem to attach the file to all e-mails, not just the (in my case) da/order_conf ? Link to comment Share on other sites More sharing options...
sm5k Posted February 20, 2014 Share Posted February 20, 2014 Solved, I added to the file mail.php (path yoursite \ classes \ mail.php) at line 270 or so, before the comment / * send email * /, this code: if ($template == 'it/order_conf') $file = _PS_ROOT_DIR_ . '/file_da_allegare.pdf'; $message->attach(new Swift_Message_Attachment(file_get_contents($file), 'file_da_allegare.pdf', 'application/pdf')); Hi this workes great with some exceptions. The PDF is attached but with 0 KB and if i try to open it . Any Ideas what this could be? Greetz and Thank you!! Link to comment Share on other sites More sharing options...
tuk66 Posted February 21, 2014 Share Posted February 21, 2014 You have to adapt the "Mail alerts" module and PaymentModule.php class. http://www.bellini-services.com has the solution already done. Link to comment Share on other sites More sharing options...
prestare Posted March 18, 2014 Share Posted March 18, 2014 I tried this and it works - however it seem to attach the file to all e-mails, not just the (in my case) da/order_conf ? Same problem for me !! Any solutions ? Link to comment Share on other sites More sharing options...
tuk66 Posted March 18, 2014 Share Posted March 18, 2014 Don't patch Mail.php class. Rather adapt code around Mail::Send() function - PaymentModule.php, OrderHistory.php etc. Link to comment Share on other sites More sharing options...
prestare Posted March 18, 2014 Share Posted March 18, 2014 Yes, but HOW ? It's more simple to do that are you sure ? Can we juste change this line " if ($template == 'it/order_conf') " ??? Thank's for your answer ! Link to comment Share on other sites More sharing options...
prestare Posted March 18, 2014 Share Posted March 18, 2014 Hi this workes great with some exceptions. The PDF is attached but with 0 KB and if i try to open it . Any Ideas what this could be? Greetz and Thank you!! Also have this one now ................. Link to comment Share on other sites More sharing options...
prestare Posted March 19, 2014 Share Posted March 19, 2014 Someone ?Just to know how to put the PDF file only with 1 template please Link to comment Share on other sites More sharing options...
marksiii Posted June 1, 2015 Share Posted June 1, 2015 Prestashop 1.6.0.14. It does not work. Link to comment Share on other sites More sharing options...
marksiii Posted June 1, 2015 Share Posted June 1, 2015 Solved, I added to the file mail.php (path yoursite \ classes \ mail.php) at line 270 or so, before the comment / * send email * /, this code: if ($template == 'it/order_conf') $file = _PS_ROOT_DIR_ . '/file_da_allegare.pdf'; $message->attach(new Swift_Message_Attachment(file_get_contents($file), 'file_da_allegare.pdf', 'application/pdf')); Prestashop 1.6.0.14 It does not work. Link to comment Share on other sites More sharing options...
MichałM Posted December 3, 2015 Share Posted December 3, 2015 In 1.6 use following code: $file_attachement['content'] = file_get_contents(_PS_ROOT_DIR_.'/file.pdf'); $file_attachement['name'] = 'Filename'; $file_attachement['mime'] = 'application/pdf'; Link to comment Share on other sites More sharing options...
Danijelp Posted March 20, 2016 Share Posted March 20, 2016 I can't get this to work (using 1.6.0.14). Here is my code: // Multiple attachments? if (!is_array(current($file_attachment))) $file_attachment = array($file_attachment); foreach ($file_attachment as $attachment) if (isset($attachment['content']) && isset($attachment['name']) && isset($attachment['mime'])) $message->attach(new Swift_Message_Attachment($attachment['content'], $attachment['name'], $attachment['mime'])); } // Your terms of service pdf $file_attachment['content'] = file_get_contents(_PS_ROOT_DIR_.'/dokumenti/file.pdf'); $file_attachment['name'] = 'file.pdf'; $file_attachment['mime'] = 'application/pdf'; /* Send mail */ Does anything else must be Please help!!! Link to comment Share on other sites More sharing options...
vikka Posted April 2, 2016 Share Posted April 2, 2016 any solusions for this ?? Link to comment Share on other sites More sharing options...
tuk66 Posted April 2, 2016 Share Posted April 2, 2016 Patching core PrestaShop code is not the best approach. It can collide with other code or modules and you have to apply the patch again after every upgrade. I suggest to use one PDF attachment (invoice) and add another page(s) to it. Alternatively, you can just put a link to a static PDF document to download. Link to comment Share on other sites More sharing options...
SilviaPimenta Posted March 15, 2017 Share Posted March 15, 2017 Hello, I have a problem similar to the one above. My problem is that I need to add more than file in the email attachment, but I can not, I can upload the two attachments but I can not send it by email. My code is as follows: for ($i=0; $i <count($_FILES['FILE']['name']); $i++) { if(!isset($_FILES['FILE'][$i]) or !($_FILES['FILE']['size'][$i] > 0)) { $this->_error .= $this->displayError($this->l('Invalid file')); } $explode = explode('.', $_FILES['FILE']['name'][$i]); $ext = end($explode); if(!in_array($ext, array('pdf','doc', 'docx', 'rar', 'zip')) ) { $this->_error .= $this->displayError($this->l('Invalid file extension')); } else { $tmpFilePath[$i] = $_FILES['FILE']['tmp_name'][$i]; if ($tmpFilePath != ""){ $newFilePath[$i] = dirname(__FILE__ ).'/import/' . $_FILES['FILE']['name'][$i]; if(move_uploaded_file($tmpFilePath[$i], $newFilePath[$i])) { $file_name[$i] = $_FILES['FILE']['name'][$i]; $file_size[$i] = $_FILES['FILE']['size'][$i]; $tmp_name[$i] = $_FILES['FILE']['tmp_name'][$i]; $file_type[$i] = $_FILES['FILE']['type'][$i]; // attachment $handle = fopen($newFilePath[$i], "r"); $content = fread($handle, $file_size[$i]); fclose($handle); $content = $content; } } } } $sql1 = 'SELECT `envio_recibo` FROM `'._DB_PREFIX_.'contabilidade_faturacao` WHERE `id_contabilidade_faturacao` ='.$id_contabilidade_faturacao; $value = Db::getInstance()->ExecuteS($sql1); foreach($value as $key => $res) {$envio_recibo = $res['envio_recibo'];} if($envio_recibo == 0) { $res = Mail::Send( $this->context->language->id, 'recibos', $subject, array('{message}' => $msg_html, $template_vars = false,), $to, $to_name, $from, $from_name, array('content' => $content, 'mime' => 'application/pdf', 'name' => $file_name[$i]), null, $this->local_path.'mails/', null, null, $bcc, null ); (continue) Do not call my texts because I am Portuguese and they are Portuguese. Can someone give me a hand? Hello, I have a problem similar to the one above. My problem is that I need to add more than file in the email attachment, but I can not, I can upload the two attachments but I can not send it by email. My code is as follows: Can someone give me a hand? Link to comment Share on other sites More sharing options...
U9sx7165b Posted April 24, 2017 Share Posted April 24, 2017 I would like to sell digital files. So when someone has ordered and the payment is done, the confirmation email contents a pdf or jpg file. Is this possible prestashop? Link to comment Share on other sites More sharing options...
tuk66 Posted April 24, 2017 Share Posted April 24, 2017 Of course, sell virtual products and upload your file as an attachment. Link to comment Share on other sites More sharing options...
Recommended Posts