In my .env file I have the following:
IMAP_HOSTNAME_TEST=imap.gmail.com
IMAP_USERNAME_TEST=myemail@gmail.com
IMAP_PASSWORD_TEST=mypw
Now I
It's a better idea to put your configuration variables in a configuration file.
In your case, I would suggest putting your variables in config/mail.php like:
'imap_hostname' => env('IMAP_HOSTNAME_TEST', 'imap.gmail.com')
And refer to them by
config('mail.imap_hostname')
It first tries to get the configuration variable value in the .env file and if it couldn't find the variable value in the .env file, it will get the variable value from file config/mail.php.