How can I set config.php values from panel?

I’m interested in setting config options from the panel, in this case I want to allow the user to edit the email transport settings in config.php:

'email' => [
    'transport' => [
      'type'     => 'smtp',
      'host'     => 'smtp.domain.com',
      'port'     => 587,
      'security' => true,
      'auth'     => true,
      'username' => 'email@domain.com',
      'password' => 'mypasswordisbad'
    ]
]

Given that the kirby() object is not availabile at this point, how do I set/override config options with values set in the panel? This code runs in a snippet that handles the route for sending email fulfilment?

I effectively want to do something like this:

$kirby = kirby();
$email = $kirby->site()->find('email-settings');

'email' => [
    'transport' => [
      'type'     => 'smtp',
      'host'     => (string)$email->host(),
      'port'     => (string)$email->port(),
      'security' => (string)$email->security(),
      'auth'     => (string)$email->auth(),
      'username' => (string)$email->username(),
      'password' => (string)$email->password()
    ]
]

Thanks for your help.

The only way to use the site or kirby objects in config is within the ready option:

Thank you, Sonja. Works great!

This looks interesting but even with the documentation I’d have no idea how this would work.

For example, how would you use something like this to have an option to enable or disable the kirby debugger? I was thinking about what something like this could be used for and this was the only real thing I could think of that I edit the config file most of the time to do.

The ready option usually does not make sense for enabling/disabling the debugger, unless you want an editor to set this (not advisable, because debugging should be off on a production server and users might accidentally set in to on permanently) or if you want to enable it for logged-in users (example in the docs). It is useful for those options that need access to the kirby and site options, like in the use case described above or like in the example in the docs.