Jump to content

Attach Pdf On Emails


Recommended Posts

OK yesterday i made some research and finally i attached invoices.pdf on mails but still cant make it work good!

the problem now is that i see blank pdf file :(

 

i added these lines on Mail.php

if(strpos($template,'payment')) {
$message->attach(new Swift_Message_Attachment(file_get_contents("/pdf-invoice.php?id_order=" . $template_vars['{id_order}']), "invoice.pdf", "application/pdf"));}

 

Any way to fix blank mails? I think something is wrong with my "path" of generated pdfs.

 

 

Result i m getting in payment mails is an attached blank file with name "invoice.pdf" 0kb

Edited by guybrush07 (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...

Hello,

 

I've solved this issue on Prestashop 1.4.9 You have to add the following on /classes/Mail.php on the function Send() just before the line with the comment: /* Send mail */ (in my file line 201):

 

if (strpos($template, 'payment')){
   $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']));
  }

 

This code attaches the invoice to 'Payment accepted' emails. If you want to attach the invoice to other emails just find the name of the template's mail and add it to the condition on the if statement. For example, if you want to attach the invoice too on the Shipped emails your code should look like this:

 

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']));
  }

 

I hope this help somebody, I googled around but I've found a lot of questions about this but no answer.

 

Ivan.

Link to comment
Share on other sites

  • 2 weeks later...
Hello, I've solved this issue on Prestashop 1.4.9 You have to add the following on /classes/Mail.php on the function Send() just before the line with the comment: /* Send mail */ (in my file line 201):
 if (strpos($template, 'payment')){ $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'])); } 

This code attaches the invoice to 'Payment accepted' emails. If you want to attach the invoice to other emails just find the name of the template's mail and add it to the condition on the if statement. For example, if you want to attach the invoice too on the Shipped emails your code should look like this:

 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'])); } 

I hope this help somebody, I googled around but I've found a lot of questions about this but no answer. Ivan.

 

I have tried the above code on 1.5.4 but to no avail. :( I did notice that it uses $template_vars now instead of $templateVars though. Changed it but still no dice. Is there perhaps an update on this available somewhere? Some help would be greatly appreciated!

Link to comment
Share on other sites

  • 2 months later...
×
×
  • Create New...