i need to send an automatic email response after a user signs up through a form.
once i get the data in the route plugin through POST from the frontend, i was thinking it was possible to
try {
$kirby->email([
'from' => 'welcome@supercompany.com',
'to' => 'someone@gmail.com',
'subject' => 'Welcome!',
'body'=> 'It\'s great to have you with us',
]);
} catch (Exception $error) {
echo $error;
}
but $kirby
is not accessible. i tried to set a callback to the route plugin like so
Kirby::plugin('your/plugin', [
'routes' => function ($kirby) {
return [
[
'pattern' => 'something',
'action' => function () {
try {
$kirby->email([
'from' => 'welcome@supercompany.com',
'to' => 'someone@gmail.com',
'subject' => 'Welcome!',
'body'=> 'It\'s great to have you with us',
]);
} catch (Exception $error) {
echo $error;
}
}
]
];
}
]);
but not working as well. then i tried to set up a route:after
hook, and the hook works once the route above gets visited, but i don’t know how to pass the data to it?
(i thought of making a GET call to the route where i send the form data, but i don’t think you can nest hooks within hooks right?)
i guess i can setup a controller to make the GET call and use the form data to send the email, as i imagine in the controller i can use the $kirby
object.
but is there any better and simpler approach to this?