Email templates: Email template attachment
{attachment}Â is powerful template function can be used when creating email templates to attach files to emails.Â
Usage
In email templates you wish to attach something, use following tag:
{attachment [attributes]}
Available attributes:
Attribute Name | Type | Required | Description |
---|---|---|---|
invoice | Invoice ID | No | Use this if you want to attach invoices to your email. Do not mix with file and template |
file | path | No | Path to your file that you wish to attach, use absolute paths. Do not mix with invoice and template |
template | int | No | ID of template to generate PDF document out of. Do not mix with invoice and file |
name | string | No | Override filename that will be used for attached file |
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:
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) :
{attachment template=ID}
If you wish to assign additional variables from email, you can pass them as attribute to attachment function:
{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
{attachment 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
{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
{attachment file="/var/acces/`$service.name`.key"}