chris2407 Posted October 23, 2010 Share Posted October 23, 2010 Hello,i was wondering if it is possible to add a Attachment to a Email? For example i want to add a PDF file which is saved on my server to the order confirmation email. And i also want to attach the Invoice.pdf to the Payment confirmation email...Can you please tell me how i can do this?many thanks, chris Link to comment Share on other sites More sharing options...
rocky Posted October 24, 2010 Share Posted October 24, 2010 PrestaShop already attaches the shop's logo to the email. The code to do that is on line 94 of classes/Mail.php (in PrestaShop v1.3.2): $templateVars['{shop_logo}'] = (file_exists(_PS_IMG_DIR_.'logo.jpg')) ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_.'logo.jpg'))) : ''; I'm sure there's a way to add a PDF in a similiar way. Link to comment Share on other sites More sharing options...
chris2407 Posted October 24, 2010 Author Share Posted October 24, 2010 yes looks good but i think this code needs to be modified a little... and i dont want to include the file to every email just to the order confirmation...could it work like this? Or do i have to write the css variable 'attachment1' in another file or something?$templateVars['{attachment1}'] = (file_exists(_PS_IMG_DIR_.'attachment1.pdf')) ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_.'attachment1.pdf'))) : ''; Link to comment Share on other sites More sharing options...
rocky Posted October 24, 2010 Share Posted October 24, 2010 No, that won't work. You'll need something like: if ($template == 'order_conf') $message->attach(new Swift_Message_Attachment(file_get_contents("invoice.pdf"), "invoice.pdf", "application/pdf")); Link to comment Share on other sites More sharing options...
chris2407 Posted October 24, 2010 Author Share Posted October 24, 2010 Will it work with that code? I just have to paste this code into the mail.php ? But where has the invoice.pdf file to be stored? Link to comment Share on other sites More sharing options...
rocky Posted October 24, 2010 Share Posted October 24, 2010 It isn't stored, it is generated. If you aren't already storing it somewhere, you will have to get the generated one. if ($template == 'order_conf') $message->attach(new Swift_Message_Attachment(file_get_contents("/pdf-invoice.php?id_order=" . $templateVars['{id_order}']), "invoice.pdf", "application/pdf")); You will also need to change lines 324 of classes/PaymentModule.php from: $data = array( to: $data = array( '{id_order}' => $order->id, This should generate the PDF invoice for order and attach it to the message. Link to comment Share on other sites More sharing options...
chris2407 Posted October 24, 2010 Author Share Posted October 24, 2010 Ok perfect i try this later. But what if the PDF file was already generated? Will this one be used then or will both have the same invoice number?I found another code in a German Prestashop forum to attach files to E-mails. But i think this will not work for the pdf invoice as this code will not generate the invoice...Mail.php Line 137: // Germanized 18.10.2010 attach pdf: http://www.homepage-community.de/index.php?topic=1623.0 if(strpos($template,'order_conf') !== false && file_exists($templatePath.$iso.'/terms.pdf')){ $message->attach(new Swift_Message_Attachment(new Swift_File($templatePath.$iso.'/terms.pdf'))); } What do you think about this code will it work fine? Link to comment Share on other sites More sharing options...
rocky Posted October 24, 2010 Share Posted October 24, 2010 That will work if you want to send a single PDF file from your mails directory to all your customers, but not if you want to send a different invoice for each order. You will need to use my code above to do that. You don't to worry about generating the PDF invoice multiple times. It won't cause the invoice number to increment. It will just use the same invoice number. Link to comment Share on other sites More sharing options...
Stefand Posted November 6, 2010 Share Posted November 6, 2010 @rockyI need this code also to add the pdf into the mail order_conf.But in your post with this code: if ($template == 'order_conf') $message->attach(new Swift_Message_Attachment(file_get_contents("/pdf-invoice.php?id_order=" . $templateVars['{id_order}']), "invoice.pdf", "application/pdf")); You tell not where I need to place that code...Can you tell me that.. Link to comment Share on other sites More sharing options...
rocky Posted November 6, 2010 Share Posted November 6, 2010 Add it after line 93 of classes/Mail.php (the $message = line). Link to comment Share on other sites More sharing options...
Stefand Posted November 6, 2010 Share Posted November 6, 2010 I have try that right know, but now I get no e-mail...So it works not?Do you have any idea why? Link to comment Share on other sites More sharing options...
Stefand Posted November 6, 2010 Share Posted November 6, 2010 I get the mails, sorry my mistake..But it has no attachment? Link to comment Share on other sites More sharing options...
rocky Posted November 6, 2010 Share Posted November 6, 2010 I have no idea. I didn't actually test that code. It should logically work. The file_get_contents function call should get the PDF invoice, then the Swift_Message_Attachment object should save it as a PDF called invoice.pdf, then $message->attach should attach it to the email. I can't think of why it wouldn't work. Link to comment Share on other sites More sharing options...
Stefand Posted November 6, 2010 Share Posted November 6, 2010 I use version 1.3.2..Can you test it by yourself please, I will pay if this works. Link to comment Share on other sites More sharing options...
Justus Posted February 3, 2011 Share Posted February 3, 2011 Hi Rocky, I would like to do the same but I installed the one page checkout module. As far as I understand, the module creates new classes/mail.php and classes/paymentmodule.php files. The original files were renamed mail.php.opbak and paymentmodule.php.opbak. The new files that were created by the module look completely different and I cannot even find the lines where I should include the code you posted. Do you know whether it's possible to attach the invoice to emails with the one page checkout module installed. If so, do I need a different code and where do I have to paste it?I don't know if you have access to the one page checkout code of mail.php and paymentmodule.php files. Let me know if not and I will paste it here.It would be amazing if you could help me here. Link to comment Share on other sites More sharing options...
holle75 Posted February 18, 2011 Share Posted February 18, 2011 trying to do the same (attach invoice to payment accepted mail) thing. Rockys solution did not work in my case. Did anybody solve this?bestH. Link to comment Share on other sites More sharing options...
nzrobert Posted February 27, 2011 Share Posted February 27, 2011 can any one confirm this works? Link to comment Share on other sites More sharing options...
nzrobert Posted February 28, 2011 Share Posted February 28, 2011 Rocky,I deleted the if ($template == 'order_conf') part and i am getting invoices on all attachments which is a good sign.There may be an issue with the if statement, is there even a template called order_conf?Also the attachments seem to be corrupt, i cant open them :-( Link to comment Share on other sites More sharing options...
rocky Posted February 28, 2011 Share Posted February 28, 2011 Yes, there should be mails//order_conf.html and order_conf.txt should exist for all languages. Link to comment Share on other sites More sharing options...
przemossj4 Posted March 10, 2011 Share Posted March 10, 2011 variable $ template in my case is equal "/order_conf" but there is still a problem because attachments in mail are only 0 kb Link to comment Share on other sites More sharing options...
Alex PSV1.6 Posted October 30, 2012 Share Posted October 30, 2012 Hi all, I studied the post above but I'm still confused how to get a quilty invoice into the status mail. Best way would be to send the invoice attached to the "shipped" status. Can anyone give me an update on that how to do that? Thanks in advance Alexander Link to comment Share on other sites More sharing options...
Scnd Posted March 9, 2013 Share Posted March 9, 2013 (edited) I managed to include a static pdf with this code: #file classes/Mail.php, line 270 (before "Send Mail" comment) if ($template == 'en/order_conf') $message->attach(new Swift_Message_Attachment(file_get_contents("/full-path/home/example/public_html/attachment.pdf"), "attachment.pdf", "application/pdf")); Edited March 9, 2013 by Scnd (see edit history) Link to comment Share on other sites More sharing options...
edinsof Posted April 19, 2013 Share Posted April 19, 2013 @Scnd code works for send specific pdf but how send invoice of accepted payment (order invoice) Link to comment Share on other sites More sharing options...
Yonkiedoodle Posted June 5, 2013 Share Posted June 5, 2013 @Scnd code works for send specific pdf but how send invoice of accepted payment (order invoice) I've been wondering about that too! I did find this thread though: http://www.prestashop.com/forums/topic/226737-attach-pdf-on-emails/ But pity it didn't work out either. Link to comment Share on other sites More sharing options...
Yonkiedoodle Posted June 6, 2013 Share Posted June 6, 2013 (edited) This is the line of code I am using, and a pdf gets sent, but it seems corrupt and cant open it: $message->attach(new Swift_Message_Attachment(file_get_contents("/pdf-invoice.php?id_order=" . $templateVars['{id_order}']), "invoice.pdf", "application/pdf")); Its probably because the pdf-invoice.php bit actually needs the customers login session in order for it to work. if (strpos($template, 'payment' || strpos($template, 'shipped')){ $id_factura = $templateVars['{id_order}']; $orden = new Order($id_factura); $factura['content'] = PDF::invoice($orden, 'S'); $factura['name'] = $id_factura.'.pdf'; $factura['mime'] = 'application/pdf'; $message->attach(new Swift_Message_Attachment($factura['content'], $factura['name'], $factura['mime'])); } Edited June 6, 2013 by Yonkiedoodle (see edit history) Link to comment Share on other sites More sharing options...
nakiodev Posted August 4, 2013 Share Posted August 4, 2013 Hi, I have a similar problem. I would like to send a specific PDF file (with the terms and conditions of use) attached to the registration email client. Do you have any suggestions? Link to comment Share on other sites More sharing options...
mani313 Posted January 27, 2014 Share Posted January 27, 2014 hello there, i want to attach a file (example.jpg) in mailalerts module. i tried with your code. it does not work . please help me out with this. thanks in advance. #mailalerts.php line 386 if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.txt') && file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.html')){ $template->attach(new Swift_Message_Attachment(file_get_contents("path/images/logo.png"), "logo.png", "image/png")); Mail::Send( $id_lang, $template, sprintf(Mail::l('New order - #%06d', $id_lang), $order->id), $template_vars, explode(self::__MA_MAIL_DELIMITOR__, $this->_merchant_mails), null, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], null, null, dirname(__FILE__).'/mails/' ); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now