Skip to main content
With the $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
{{= $wsEmails | json }}
JSON output
{
  "sendConfiguredEmail": "ƒ()"
}
Note: "ƒ()" denotes a function. Methods overview
MethodReturn typeDescription
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 under messages. The email ID corresponds to the name of the configuration. Signature
$wsEmails.sendConfiguredEmail(emailId)

Return value\

Parameters
NameTypeRequiredDescription
emailIdstringyesID of the email from the messages configuration (e.g. "orderConfirmation", "contactForm").
Call (always wrap it in a condition, see example):
{{ $wsEmails.sendConfiguredEmail("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.
{{ var $contact = $wsActions.create("ContactForm") }}

<form method="POST" action="{{= $wsViews.current.url() }}">
  <input type="hidden" name="wscsrf" value="{{= $contact.csrf }}">
  <input type="text" name="message" placeholder="Your message">
  <button type="submit" name="wsact" value="{{= $contact.id }}">Send</button>
</form>

{{ if $contact.success }}
  {{ $wsEmails.sendConfiguredEmail("contactForm") }}
  Thank you, your message has been sent.
{{ /if }}
Result
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.

  • messages - Event-driven emails – defines the sendable emails (content, recipients, ID) that sendConfiguredEmail() accesses.
  • $wsActions – provides the success status with which you guard the sending.