# Uniform send custom reply

**URL:** <https://forum.getkirby.com/t/uniform-send-custom-reply/3401>\
**Category:** Questions\
**Tags:** v2\
**Created:** [February 23, 2016, 12:43pm UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401 "2016-02-23T12:43:53Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![krisa](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/krisa/32/3415_2.png) [@krisa](https://forum.getkirby.com/u/krisa)\
**Post date:** [February 23, 2016, 12:43pm UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/1 "2016-02-23T12:43:53Z")

</div>

Hi, i am hsing uniform plugin and i need to send second email to the client. Not the copy but the thank you email.  
Its tragic. Of course i know shit about php. So i ask for help of this cool comunity.

Uniform actions:

```auto
                array(
                    '_action' => 'email',
                    'to' => (string)$site->formrecipient(),
                    'sender' => (string)$site->formsender(),
                    'subject' => 'Client message',
                    'snippet' => 'uniform-email-contact'
                ),
                   array(
                    '_action' => 'email', 
                    'to' => a::get($form, '_from'), 
                    'sender' => (string)$site->formsender(),
                    'subject' => 'Thank you Client!',
                    'snippet' => 'uniform-email-thanks'
                ),

```

This is the problematic part

```auto
'to' => a::get($form, '_from'),

```

I asume i cant get the value at initialisation. But how do ido that.

THANKS

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [February 23, 2016, 1:34pm UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/2 "2016-02-23T13:34:35Z")

</div>

That would be something like `get('_from')`.  
`get()` is a Kirby helper that returns the GET/POST value.

By the way: Please format your code blocks using three backticks at the start and end. I have done it for your post. You can click the pencil icon of your post to see how that syntax works.

---

<div class="post-metadata">

**Author:** ![krisa](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/krisa/32/3415_2.png) [@krisa](https://forum.getkirby.com/u/krisa)\
**Post date:** [February 23, 2016, 4:59pm UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/3 "2016-02-23T16:59:57Z")

</div>

Yes.

It works, thanks!

---

<div class="post-metadata">

**Author:** ![aftereffectsmagic](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aftereffectsmagic](https://forum.getkirby.com/u/aftereffectsmagic)\
**Post date:** [March 1, 2016, 2:15am UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/4 "2016-03-01T02:15:12Z")

</div>

What was the final code used for the controller? I’m encountering the same problem and `get('_'from')` doesn’t seem to work for me. I have a list of `allowed-recipients` and that e-mail action works perfectly, but the user confirmation / thank you e-mail just below it does not work (invalid `to:` address).

Here’s my code:

```auto
            array(
               '_action' => 'email-select',
               'sender' => 'example@example.com',
               'subject' => 'Web Contact from {name}',
               'snippet' => 'uniform-email-table',
               'replyTo' => isset($options['replyTo']) ? $options['replyTo'] : a::get($form, '_from'),
               'allowed-recipients' => array(
                  'example1' => 'example1@example.com',
                  'example2' => 'example2@example.com',
                  'example3' => 'example3@example.com',
                  'example4' => 'example4@example.com'
                  )
               ),
            array(
               '_action' => 'email', 
               'sender' => 'example@example.com',
               'subject' => 'Thank You For Contacting Us, {name}!',
               'to' => 'get('_from')',
               'message' => 'Thank you for contacting us today. We will be in touch soon!'
            )
         )

```

Thanks for any help you can provide!

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 1, 2016, 5:55am UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/5 "2016-03-01T05:55:01Z")

</div>

You’ve got quotes around `get('_from')`, try removing them.

---

<div class="post-metadata">

**Author:** ![aftereffectsmagic](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aftereffectsmagic](https://forum.getkirby.com/u/aftereffectsmagic)\
**Post date:** [March 1, 2016, 7:25pm UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/6 "2016-03-01T19:25:43Z")

</div>

Thanks, @texnixe- removing the quotes around `get('_from')` worked like a charm.

One more question- I’d like to customize the sender in the second e-mail message. Depending on what department the user chooses in the form, can I customize the sender e-mail address?

It would be something like:

```auto
'allowed-senders' => array(
                  'example1' => 'example1@example.com',
                  'example2' => 'example2@example.com',
                  'example3' => 'example3@example.com',
                  'example4' => 'example4@example.com'
                  )
'sender' => {allowed-senders},

```

How can I make this concept work? This would be super useful so the user has a direct e-mail address to reply to in his / her e-mail confirmation.

Thanks!

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 1, 2016, 7:33pm UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/7 "2016-03-01T19:33:55Z")

</div>

Is this what your are looking for: [https://github.com/mzur/kirby-uniform/wiki/Action:-Email-select](https://github.com/mzur/kirby-uniform/wiki/Action:-Email-select)

---

<div class="post-metadata">

**Author:** ![aftereffectsmagic](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aftereffectsmagic](https://forum.getkirby.com/u/aftereffectsmagic)\
**Post date:** [March 1, 2016, 7:45pm UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/8 "2016-03-01T19:45:29Z")

</div>

In a sense, yes.  
##First e-mail (To Allowed Recipients)  
The first e-mail is directed to a recipient based on what the user selects in the form- `allowed-recipients`. Works perfectly as is in the first code snippet I posted above (`'action' => 'email-select'`).  
##Second e-mail (To user from Allowed Senders)  
The second e-mail should be directed to the user (this works with `get('_from')`) but it should have a different sender depending on what department the user selects in the form- whatever e-mail address is the `allowed-recipients` should also be the sender of this e-mail- something like `allowed-senders`. That means that the `allowed-recipients` value is the same as `allowed-senders` and the user will get an email confirmation directly from the `allowed-senders` value and can reply to the right department without the e-mail going to a generic inbox.

What is the best way to go about this? I also set up another `email-select` action, but can’t get the `allowed-senders` concept to work.

Thanks so much for your help!

---

<div class="post-metadata">

**Author:** ![aftereffectsmagic](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aftereffectsmagic](https://forum.getkirby.com/u/aftereffectsmagic)\
**Post date:** [March 1, 2016, 7:50pm UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/9 "2016-03-01T19:50:59Z")

</div>

This is what I am thinking about adding to `\plugins\uniform\lib\UniForm.php` to make this concept work.

```auto
/*
 * Action Choose from multiple senders who should send the user confirmation by
 * email.
 */
uniform::$actions['email-select'] = function($form, $actionOptions) {
    $allowed = a::get($actionOptions, 'allowed-senders');

    if (!is_array($allowed))
    {
        throw new Exception('Uniform email select action: No allowed senders!');
    }

    $sender = a::get($form, '_sender');

    if (!array_key_exists($sender, $allowed))
    {
        return array(
                'success' => false,
                'message' => l::get('uniform-email-error').' '.l::get('uniform-email-select-error')
        );
    }

    unset($form['_sender']);
    unset($actionOptions['allowed-senders']);
    $actionOptions['_from'] = $allowed[$sender];

    return call_user_func(uniform::$actions['email'], $form, $actionOptions);
};

```

I will try it now and report back!

---

<div class="post-metadata">

**Author:** ![aftereffectsmagic](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aftereffectsmagic](https://forum.getkirby.com/u/aftereffectsmagic)\
**Post date:** [March 1, 2016, 8:10pm UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/10 "2016-03-01T20:10:16Z")

</div>

Got a fatal error when attempting to implement this change in `UniForm.php`:

> [@aftereffectsmagic](#):
>
> This is what I am thinking about adding to `\plugins\uniform\lib\UniForm.php` to make this concept work.

```auto
/*
 * Action Choose from multiple senders who should send the user confirmation by
 * email.
 */

uniform::$actions['email-select'] = function($form, $actionOptions) {
    $allowed = a::get($actionOptions, 'allowed-senders');

    if (!is_array($allowed))
    {
        throw new Exception('Uniform email select action: No allowed senders!');
    }

    $sender = a::get($form, '_sender');

    if (!array_key_exists($sender, $allowed))
    {
        return array(
                'success' => false,
                'message' => l::get('uniform-email-error').' '.l::get('uniform-email-select-error')
        );
    }

    unset($form['_sender']);
    unset($actionOptions['allowed-senders']);
    $actionOptions['_from'] = $allowed[$sender];

    return call_user_func(uniform::$actions['email'], $form, $actionOptions);
};

```

Ideas on how to achieve the same thing for `allowed-senders` that @mzur set up for `allowed-recipients`? It’s the exact same concept, only the other way around.

---

<div class="post-metadata">

**Author:** ![mzur](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@mzur](https://forum.getkirby.com/u/mzur)\
**Post date:** [March 3, 2016, 6:48pm UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/11 "2016-03-03T18:48:25Z")

</div>

What does the fatal error say? Note that `_from` must be set in the `$form` array and not the `$actionOptions`.

---

<div class="post-metadata">

**Author:** ![mkeipert](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@mkeipert](https://forum.getkirby.com/u/mkeipert)\
**Post date:** [September 20, 2016, 6:54pm UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/12 "2016-09-20T18:54:23Z")

</div>

Hello, thank you for this thread to get the custom reply working. I now get two success-messages like “Das Formular wurde gesendet.” How do I skip the message the second time?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 20, 2016, 8:25pm UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/13 "2016-09-20T20:25:41Z")

</div>

Could you post your code, please?

---

<div class="post-metadata">

**Author:** ![mkeipert](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@mkeipert](https://forum.getkirby.com/u/mkeipert)\
**Post date:** [September 21, 2016, 9:19am UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/14 "2016-09-21T09:19:53Z")

</div>

It’s just standard-code:

```
<?php

return function($site, $pages, $page) {
    $form = uniform('contact-form', [
        'required' => [
            'Vorname' => '',
            'Nachname' => '',
            '_from' => 'email'
        ],
        'actions' => [
            [
                '_action' => 'email',
                'to' => 'mai@mail.de',
                'sender' => 'mail@mail.de',
                'subject' => 'Neue Anmeldung für {Kurs}',
                'snippet' => 'uniform-email-default'
            ],
             [
                '_action' => 'email',
                'to' => get('_from'),
                'sender' => 'mail@mail.de',
                'subject' => 'Deine Anmeldung für {Kurs}',
                'snippet' => 'uniform-email-default'
            ]
        ]
    ]);

    return compact('form');
};

```

Two messages are sent, like it should be - but the success-message ist displayed two times too: “Vielen Dank, das Formular wurde gesendet.Vielen Dank, das Formular wurde gesendet.”

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 21, 2016, 9:44am UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/15 "2016-09-21T09:44:57Z")

</div>

You can pass an index number for the action that should output the message like this

```auto
<?php $form->echoMessage(0) ?>

```

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 21, 2016, 10:05am UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/16 "2016-09-21T10:05:20Z")

</div>

To explain why that happens: Each form submission can fail, so there are two separate messages. You can however only display one as in Sonja’s code snippet above if both have succeeded. 🙂

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 21, 2016, 10:11am UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/17 "2016-09-21T10:11:59Z")

</div>

Here is the function with its comments:

```auto
/**
     * Echos the success/error feedback message directly as a HTML-safe string.
     * Either from one specified action or from all actions.
     *
     * @param mixed $action (optional) the index of the action to get the
     * feedback message from
     */
    public function echoMessage($action = false)
    {
        echo str::html($this->message($action));
    }

```

(UniForm.php)

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:55pm UTC](https://forum.getkirby.com/t/uniform-send-custom-reply/3401/18 "2025-02-06T16:55:11Z")

</div>


