Template emails

A mail is a PAD template, rendered to an HTML part and a text part and handed to a transport. Templates live in _mail/, looked up like _include/: _mail/welcome.pad is the HTML part, _mail/welcome.txt the text part - without one, the text is made from the HTML - and _mail/welcome.php runs first. _inits.pad and _exits.pad in the same _mail/ are the email's layout, with @page@ where the mail goes:

PHP
fragments/mail_1.php
HTML
fragments/mail_1.pad
Result
<?php

padMail
( 'ann@example.com', 'welcome', 'Welcome to the shop', [ 'name' => 'Ann' ] );

$mail = $padMailLast;

?>
<p>To {$mail.to}: <b>{$mail.subject}</b></p>
{$mail.text}
{!mail.html}

To ann@example.com: Welcome to the shop

Welcome, Ann!

Your account is ready: sign in (https://example.com/account).

-- The shop

Welcome, Ann!

Your account is ready: sign in.

-- The shop

From a template, {mail} sends the same way. With a template it is {mail to=$email, template='welcome', subject='Welcome'}; as a pair, the content is the HTML part, rendered where it stands - in a loop with the fields of the row:

PHP
fragments/mail_2.php
HTML
fragments/mail_2.pad
Result
<?php

$name
= 'Ann';

?>
{mail to='ann@example.com', subject='Your order'}
<p>Thank you for your order, {$name}.</p>
{/mail}
<p>Sent: {$padMailLast.subject}</p>

Sent: Your order