> ## 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.

# Newsletter

> Reference for WEBSALE newsletter actions used to subscribe customers, confirm subscriptions via opt-in and unsubscribe from mailings.

This section describes the available actions in the Newsletter area. With these actions, customers can subscribe to the newsletter, confirm their subscription, and unsubscribe again.

***

## Actions overview

| **Action**                     | **Description**                                           |
| ------------------------------ | --------------------------------------------------------- |
| `NewsletterSubscribe`          | Subscribes a customer to the newsletter.                  |
| `NewsletterSubscribeConfirm`   | Confirms the newsletter subscription via double opt-in.   |
| `NewsletterUnsubscribe`        | Unsubscribes a customer from the newsletter.              |
| `NewsletterUnsubscribeConfirm` | Confirms the newsletter unsubscription via double opt-in. |

***

## Actions

### NewsletterSubscribe

This action subscribes a customer to the newsletter. After successful subscription, the customer receives a confirmation email with a double opt-in link.

**Usage example**\
Can be used on a newsletter subscription page where customers can enter their email address and optionally select one or more target groups.

**Parameters**

| **Name**             | **Description**                                                      |
| -------------------- | -------------------------------------------------------------------- |
| `email`              | The email address to be subscribed to the newsletter.                |
| `targetGroupId.(id)` | Optional target group ID to which the customer should be subscribed. |

**Error codes**

| **Error code**         | **Description**                                            |
| ---------------------- | ---------------------------------------------------------- |
| `missingEmail`         | Parameter `email` is missing.                              |
| `emailCheckFailed`     | The specified email address is invalid.                    |
| `accountAlreadyExists` | The email address is already subscribed to the newsletter. |

**Related modules, variables & methods**

* [\$wsNewsletter](/en/frontend/referenz/module/wsnewsletter)
* [\$wsNewsletter.getTargetGroups()](/en/frontend/referenz/module/wsnewsletter#\$wsnewsletter-gettargetgroups)

**Example** showing how a customer selects their email address and optionally target groups to subscribe to the newsletter, including success output after the subscription.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $myActionNewsletterSubscribe = $wsActions.create("NewsletterSubscribe") }}
<form method="post" action="{{= $wsViews.current.url() }}">
    <input type="hidden" name="wscsrf" value="{{= $myActionNewsletterSubscribe.csrf }}">
    <input type="hidden" name="wsact" value="{{= $myActionNewsletterSubscribe.id }}">
    {{ if $myActionNewsletterSubscribe.success }}
        <div class="alert alert-success">Newsletter successfully subscribed.</div>
    {{ /if }}
    {{ foreach $myNewsletterList in $wsNewsletter.getTargetGroups() }}
        <input type="checkbox" value="{{= $myNewsletterList.id }}" name="targetGroupId.{{= $myNewsletterList.id }}">
        <label>{{= $myNewsletterList.name }}</label>
    {{ /foreach }}
    <input type="email" name="email">
    <button type="submit">Subscribe to newsletter</button>
</form>
```

***

### NewsletterSubscribeConfirm

This action confirms the newsletter subscription via double opt-in. After subscribing, the customer receives an email with a confirmation link that triggers this action.

**Usage example**\
Can be used on the confirmation page to which the customer is redirected after clicking the opt-in link in the subscription email.

**Error codes**

| **Error code** | **Description**                   |
| -------------- | --------------------------------- |
| `unauthorized` | No valid opt-in token was passed. |

**Related modules, variables & methods**

* [\$wsNewsletter](/en/frontend/referenz/module/wsnewsletter)

**Example** showing how a success message is displayed after successful confirmation and an error notice appears in the event of an invalid token.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $myActionNewsletterSubscribeConfirm = $wsActions.create('NewsletterSubscribeConfirm') }}
<form method="post" action="{{= $wsViews.current.url() }}">
    <input type="hidden" name="wscsrf" value="{{= $myActionNewsletterSubscribeConfirm.csrf }}">
    <input type="hidden" name="wsact" value="{{= $myActionNewsletterSubscribeConfirm.id }}">
    {{ if $myActionNewsletterSubscribeConfirm.success }}
        <div class="alert alert-success">Newsletter successfully subscribed.</div>
    {{ else }}
        {{ include "components/errorAlert.htm" with $cAction = $cActionNewsletterSubscribeConfirm }}
        <button type="submit">Confirm subscription.</button>
    {{ /if }}
</form>
```

***

### NewsletterUnsubscribe

This action unsubscribes a customer from the newsletter. The customer specifies their email address and can optionally deselect individual target groups.

**Usage example**\
Can be used on the unsubscribe page, where customers can enter their email address and unsubscribe from individual or all newsletter target groups.

**Parameters**

| **Name**             | **Description**                                                          |
| -------------------- | ------------------------------------------------------------------------ |
| `email`              | The email address to be unsubscribed from the newsletter.                |
| `targetGroupId.(id)` | Optional target group ID from which the customer should be unsubscribed. |

**Error codes**

| **Error code**     | **Description**                         |
| ------------------ | --------------------------------------- |
| `missingEmail`     | Parameter `email` is missing.           |
| `emailCheckFailed` | The specified email address is invalid. |

**Related modules, variables & methods**

* [\$wsNewsletter](/en/frontend/referenz/module/wsnewsletter)
* [\$wsNewsletter.getTargetGroups()](/en/frontend/referenz/module/wsnewsletter#\$wsnewsletter-gettargetgroups)

**Example** showing how a customer enters their email address and unsubscribes from individual target groups, including success output.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $myActionNewsletterUnsubscribe = $wsActions.create('NewsletterUnsubscribe') }}
<form method="post" action="{{= $wsViews.current.url() }}">
    <input type="hidden" name="wscsrf" value="{{= $myActionNewsletterUnsubscribe.csrf }}">
    <input type="hidden" name="wsact" value="{{= $myActionNewsletterUnsubscribe.id }}">
    {{ if $cActionNewsletterUnsubscribe.success }}
        <div class="alert alert-success">Successfully unsubscribed from the newsletter.</div>
    {{ else }}
        <input type="email" name="email" value="{{= $myActionNewsletterUnsubscribe.params.email | ifNull('') }}">
        {{ foreach $group in $wsNewsletter.getTargetGroups() }}
            {{ if not $group.deactivated }}
                <input type="checkbox" name="targetGroupId.{{= $group.id }}" value="y">
                <label>{{= $group.name }}</label>
            {{ /if }}
        {{ /foreach }}
        <button type="submit">Unsubscribe from newsletter.</button>
    {{ /if }}
</form>
```

***

### NewsletterUnsubscribeConfirm

This action confirms the newsletter unsubscription via double opt-in. After unsubscribing, the customer receives an email with a confirmation link that triggers this action.

**Usage example**\
Can be used on the confirmation page to which the customer is redirected after clicking the opt-in link in the unsubscription email.

**Error codes**

| **Error code** | **Description**                   |
| -------------- | --------------------------------- |
| `unauthorized` | No valid opt-in token was passed. |

**Related modules, variables & methods**

* [\$wsNewsletter](/en/frontend/referenz/module/wsnewsletter)

**Example** showing how a success message is displayed after successful confirmation of the unsubscription and an error notice appears in the event of an invalid token.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $myActionNewsletterUnsubscribeConfirm = $wsActions.create('NewsletterUnsubscribeConfirm') }}
<form method="post" action="{{= $wsViews.current.url() }}">
    <input type="hidden" name="wscsrf" value="{{= $myActionNewsletterUnsubscribeConfirm.csrf }}">
    <input type="hidden" name="wsact" value="{{= $myActionNewsletterUnsubscribeConfirm.id }}">
    {{ if $cActionNewsletterUnsubscribeConfirm.success }}
        <div class="alert alert-success">Successfully unsubscribed from the newsletter.</div>
    {{ else }}
        <button type="submit">Confirm unsubscription.</button>
    {{ /if }}
</form>
```
