Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

{attachment} is powerful template function can be used when creating email templates . It will allow you to include pdf invoices or normal files.to attach files to emails. 

Usage

...

In email templates you wish to attach something, use following tag:

Wiki Markup
{attachment [attributes]}

Available attributes:

name
Attribute NameTypeRequiredDescription
invoiceInvoice IDNoUse this if you want to attach invoices to your email. Do not mix with file and template
filepathNoPath to your file that you wish to attach, use absolute paths. Do not mix with invoice and template
templateintNoID of template to generate PDF document out of. Do not mix with invoice and file
namestringNoOverride filename that will be used for attached file

Usage

Example usage in email templates:

...

Generating & attaching PDF document "on-the-fly"

...

Using document templates created/customised in Settings→Billing→Document Templates you can generate PDF document with dynamic content and attach it to email. 

In template details you will be presented with usage of attachment function:

Image Added

Note: In your document template you will have access to same variables as in email template that you're attaching pdf to.


Once you will define your pdf template contents you can attach it to email template using (Replace ID below with your actual template id) :

Code Block
languagephp
{ifattachment $invoice}
  {attachment invoice=$invoice.id}
{/if}

...

template=ID}


If you wish to assign additional variables from email, you can pass them as attribute to attachment function:

Code Block
languagephp
{attachment template=ID foo='value1' bar='value2'}

Then in your document templates you can refer to variable you've created as {$foo} {$bar}.



Attaching PDF invoices

...

In any email template you can attach PDF invoice if you know its id

Code Block
languagetextphp
{attachment file="/var/acces/`$service.name`.key"}

...

invoice=$invoice.id}


Attaching any existing file

...

If you know file location in your HostBill filesystem you can attach it to your emails by passing absolute path to it in file attribute


Code Block
languagephp
{if $invoice.gateway == 'Bank Transfer'}
  {attachment file="/var/pdfguides/banktransferguide.pdf" name="Bank Transfer Guide.pdf"}
{/if}


You can also use variables in file path

Code Block
languagetext
{attachment file="/var/acces/`$service.name`.key"}