EMailing and templates

In many applications you will need to send templated emails...

Whether you need to send confirmation emails to your users or want to implement a pdf form, templates play an important role when you need to customize standard text with variables. In PHsPeed there is a template component that can be used for just this. In the most basic form, you can assign a text to the component, and then supply the parameters that must be incorporated. In a more advanced form, you can bind the component to a data source to retrieve a template automatically and map a data table to create a bulk of processed templates that can be used to send a personalized email or to personalize a pdf, depending on the selected data.

To specify the template, you can apply variables in your text by separate them with start en end tokens. Default {% and%} is used. As an example you could have a simple template containing the following text:

Dear {%name%}
Thank you for subscribing.

The start and end token are defined in the component. To process the template you need to assign the variable:


After processing, the template would contain:

Dear John,
Thank you for subscribing.

The result of the processed template can be used as a basis for a customized email, a webpage and pdf.

Of course, you will have a component that is able to send emails. The component implements the 'phpmailer' library. Depending on your needs, you can setup an encrypted config file that supplies your email credentials, or use a preference table that has stored the credentials.

03 Mar 2021 Blog None