Skip to main content
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

ActionDescription
NewsletterSubscribeSubscribes a customer to the newsletter.
NewsletterSubscribeConfirmConfirms the newsletter subscription via double opt-in.
NewsletterUnsubscribeUnsubscribes a customer from the newsletter.
NewsletterUnsubscribeConfirmConfirms 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
NameDescription
emailThe email address to be subscribed to the newsletter.
targetGroupId.(id)Optional target group ID to which the customer should be subscribed.
Error codes
Error codeDescription
missingEmailParameter email is missing.
emailCheckFailedThe specified email address is invalid.
accountAlreadyExistsThe email address is already subscribed to the newsletter.
Related modules, variables & methods Example showing how a customer selects their email address and optionally target groups to subscribe to the newsletter, including success output after the subscription.
{{ 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 codeDescription
unauthorizedNo valid opt-in token was passed.
Related modules, variables & methods Example showing how a success message is displayed after successful confirmation and an error notice appears in the event of an invalid token.
{{ 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
NameDescription
emailThe email address to be unsubscribed from the newsletter.
targetGroupId.(id)Optional target group ID from which the customer should be unsubscribed.
Error codes
Error codeDescription
missingEmailParameter email is missing.
emailCheckFailedThe specified email address is invalid.
Related modules, variables & methods Example showing how a customer enters their email address and unsubscribes from individual target groups, including success output.
{{ 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 codeDescription
unauthorizedNo valid opt-in token was passed.
Related modules, variables & methods 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.
{{ 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>