$wsEmails module, you trigger the sending of preconfigured emails. The emails themselves are defined in the shop configuration under messages. The module triggers the sending of one of these emails by its ID.
This page covers triggering the sending. The content, recipients, and layout of the email are defined in the messages configuration, not here.
Basic concept
$wsEmails has exactly one method: sendConfiguredEmail(emailId). It sends the email whose ID matches the name in the messages configuration.
If the call sits unguarded in the template, the email is sent on every page view. To avoid this, always wrap it in a condition that only applies in the desired case, for example after a form has been submitted successfully. This way you avoid accidental multiple sending.
Module overview
Example / excerpt of$wsEmails
"ƒ()" denotes a function.
Methods overview
| Method | Return type | Description |
|---|---|---|
sendConfiguredEmail() | – | Sends an email configured under messages. |
Templates
Email sending can be triggered from any template, but only in a controlled way (see Basic concept). Typical use cases are contact forms, confirmations, or notifications after certain actions.Variables
No variables are available for$wsEmails.
Methods
$wsEmails.sendConfiguredEmail()
Sends an email defined in the shop configuration undermessages. The email ID corresponds to the name of the configuration.
Signature$wsEmails.sendConfiguredEmail(emailId)
Return value\
Parameters| Name | Type | Required | Description |
|---|---|---|---|
emailId | string | yes | ID of the email from the messages configuration (e.g. "orderConfirmation", "contactForm"). |
Actions
No actions are available for$wsEmails.
Examples
Send email only after a successful form submission
This example couples the sending to the success of a form action: only when the form has been submitted successfully (success) is the configured email triggered.
The email is only sent if the form has been submitted successfully. Simply reloading the page does not trigger sending.
The action name
ContactForm and the email ID contactForm are placeholders. Use the names configured in your shop and verify that sending only occurs in the success case.Related links
- messages - Event-driven emails – defines the sendable emails (content, recipients, ID) that
sendConfiguredEmail()accesses. - $wsActions – provides the
successstatus with which you guard the sending.
