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.
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.
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:
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, @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?
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.
Got a fatal error when attempting to implement this change in UniForm.php:
/*
* 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.
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?
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.”
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.
/**
* 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));
}