I need to modify the mail SMTP parameters such as
MAIL_HOST
andMAIL_USERNAME
dynamically.For, this I am using
Config::set()
to set these values dynamically.
# This code works
Config::set('mail.host', 'smtp.gmail.com');
Mail::to('[email protected]')->send(new myMailable());
The above code works if I do not queue the mail.
The moment I queue it, it appears that
Config::set()
fails to set the values.
Test to confirm Config::set()
not working with queued jobs -
I created a simple job and put the below code in the handler.
public function handle()
{
# set the config
Config::set('mail.host', 'smtp.gmail.com');
# confirm config has been set correctly
logger('Setting host to = [' . config('mail.host') . ']');
}
The above code creates the below log entry.
Setting host to = []
Why can I not change the Config
on-the-fly for queued jobs? And how to solve this?