> ## Documentation Index
> Fetch the complete documentation index at: https://dokumentation.websale.de/llms.txt
> Use this file to discover all available pages before exploring further.

# $wsEmails - Emails

> Trigger preconfigured shop emails (order confirmation, reminders, notifications) from the frontend in a controlled, event-driven way.

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)`](#wsemails-sendconfiguredemail). It sends the email whose ID matches the name in the `messages` configuration.

<Info>
  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.
</Info>

***

## Module overview

**Example / excerpt of** `$wsEmails`

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{= $wsEmails | json }}
```

**JSON output**

```json theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{
  "sendConfiguredEmail": "ƒ()"
}
```

Note: `"ƒ()"` 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](#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**

| **Name**  | **Type** | **Required** | **Description**                                                                                  |
| --------- | -------- | ------------ | ------------------------------------------------------------------------------------------------ |
| `emailId` | string   | yes          | ID of the email from the `messages` configuration (e.g. `"orderConfirmation"`, `"contactForm"`). |

Call (always wrap it in a condition, see example):

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ $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.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ 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.

<Note>
  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.
</Note>

***

## Related links

* [messages - Event-driven emails](/en/konfiguration/messages-ereignisgesteuerte-e-mails) – defines the sendable emails (content, recipients, ID) that `sendConfiguredEmail()` accesses.
* [\$wsActions](/en/frontend/referenz/module/wsactions) – provides the `success` status with which you guard the sending.
