{mail}
Renders a template, or its own content, to an e-mail with an HTML and a text part, and sends it.
Syntax
{mail to=$email, template='order', subject='Order confirmation'}
{mail to=$email, subject='Welcome', from='shop@example.com', cc='a@example.com', bcc='b@example.com', replyTo='help@example.com'} ... {/mail}
Options
-
to -
The address or addresses -
ann@example.com,Ann <ann@example.com>, several separated by commas. -
subject - The subject - required.
-
template -
A template in
_mail/:order.padthe HTML part,order.txtthe text part,order.phprun first. Without it the pair's content is the HTML part. -
from -
The sender,
$padMailFromby default. -
cc - Copy addresses.
-
bcc - Blind copy addresses.
-
replyTo - The Reply-To address.
Description
{mail to=$email, template='order', subject='Order confirmation'} renders _mail/order.pad to the HTML part and _mail/order.txt to the text part - made from the HTML when there is no .txt - after running _mail/order.php, inside the _inits.pad/_exits.pad of that _mail/ with @page@. The template is looked up like a snippet, from the page's directory up to the application and _common.
As a pair without template= the rendered content is the HTML part - inside a loop with the fields of the row, one mail per occurrence. The tag shows nothing; the mail sees the page's variables and leaves them as they were. from= (default $padMailFrom), cc=, bcc= and replyTo= are the other headers.
$padMailTransport decides where the mail goes: 'file' (the default) writes an .eml under DATA/mail/<app>/, keeping the newest $padMailKeep - no mail server needed; 'mail' sends through PHP's mail(); the name of an application function gets the message array and answers whether it went. A line break in a header value, an address that is none, a missing subject or template are errors. From PHP: padMail ( $to, $template, $subject, $vars, $options ), and [ 'queue' => TRUE ] sends it through the job queue.
The tag sends mail, so its examples are shown, not run.
Examples
A template from _mail/
_mail/order.pad is the HTML part and _mail/order.txt the text part - made from the HTML when there is none; the tag shows nothing.
{mail to=$email, template='order', subject='Order confirmation', replyTo='shop@example.com'}
<p>We sent a confirmation to {$email}.</p>
The content is the mail
As a pair without template= the rendered content is the HTML part - inside a loop with the fields of the row.
{customers}
{mail to=$email, subject='Your invoice', bcc='archive@example.com'}
<p>Dear {$name},</p>
<p>Invoice {$invoice} of {$amount | currency('EUR')} is ready.</p>
{/mail}
{/customers}
Where the mail goes
$padMailTransport decides: file (the default, an .eml under DATA/mail/<app>/), PHP's mail(), or a function of the application.
{# _config/config.php:
$padMailTransport = 'file'; // DATA/mail/<app>/*.eml - no mail server needed
$padMailTransport = 'mail'; // PHP mail()
$padMailTransport = 'smtpSend'; // _lib function, given the message array
$padMailFrom = 'Shop <shop@example.com>';
#}
{mail to='Ann <ann@example.com>', cc='bob@example.com', subject='Welcome'}<p>Hello Ann</p>{/mail}
See also
- {curl} Fetches a URL and answers the body of the response, optionally kept in a cache for a number of seconds.
- {page} Renders another page of the application - its PHP and its template - in place of the tag.
- {form} A form that posts back to the page, carrying the session's CSRF token and its own name, its fields refilling when it came back.