4

I have installed Roundcube webmail on my server, but I want to customise it a little but.

In the file config/defaults.inc.php, there is variable $config['smtp_user'] = '%u';

But I'd like to change this value, based on the value of $_SESSION["username"];, however the session is not started in the file, and only is in the index.php file.

I have tried setting $config['smtp_user'] inside the index.php file, which sets it fine but it doesn't work when sending mail.

Is there a way I can change this value inside my config/defaults.inc.php or config/config.inc.php file and use the value from $_SESSION["username"]

charlie
  • 415
  • 4
  • 35
  • 83
  • Can you include your code in github or somewhere we can see it? – user3585659 May 06 '20 at 01:24
  • @user3585659 i'm trying to change the value of `$config['smtp_user']` by using a session variable but the session is not started in the file `defaults.inc.php` which contains `$config['smtp_user']` – charlie May 06 '20 at 06:57
  • Why not have a default value first, then when the session start you change the value. Something like `$config['smtp_user'] = $_SESSION['nameOfSession'] ? $_SESSION['nameOfSession'] : $yourDefaultValue` – user3585659 May 07 '20 at 00:53
  • I tried this yesterday actually in the index.php file, but it didn't seem to pickup the correct value. I'm not sure whether the `$config` vars are picked up somewhere else – charlie May 07 '20 at 08:20

1 Answers1

0

You can start the session in a read-only mode and then get the username. With this solution, the session will get started in a read-only mode and then immediately closed after populating $_SESSION.

Add this to your config.inc.php:

session_start(['read_and_close' => true]);
$config['smtp_user'] = $_SESSION['username'] ?? '%u';

If you also want to modify the session (f.e. to only fill the username from session for one request), you can add this to your config.inc.php instead:

session_start();
$config['smtp_user'] = $_SESSION['username'] ?? '%u';
unset($_SESSION['username']);
session_write_close();
Furkan
  • 288
  • 1
  • 8