I’m trying to send an email to the owner of a site when a form is submitted. On the front-end, I’m using Vue, where I have an input that makes an axios request to an endpoint when the input is submitted.
I’m then listening to this endpoint in my /site/config/config.php file, and trying to send the submitted data in an email. The endpoint works fine if I’m just returning testing data, but as soon as I add the $kirby object into the endpoint action to send an email with kirby email, I keep getting 500 errors. Any ideas? Here is the code in my config.php.
<?php
return [
'routes' => function ($kirby) {
return [
[
'pattern' => 'email-signup/(:all)',
'action' => function ($all) {
// $all is the email address data
$body = 'The following email address wants to be signed up: ' . $all;
try {
$kirby->email([
'from' => 'welcome@mycompany.com',
'to' => 'someone@mycompany.com',
'subject' => 'Welcome!',
'body'=> $body,
]);
} catch (Exception $error) {
return $error;
}
return 'success';
},
'method' => 'POST'
]
];
}
];