问题
I want to set the following setting dynamically before I notify the user.
MAIL_DRIVER=
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_SENDER_EMAIL=
MAIL_SENDER_NAME=
for each customer they have the option to set this value from the frontend now I need to send email as per there setting is there any way in laravel I can do this.
I am using notification to notify each customer so before I notify I want to set this option dynamically from DB.
Thanks in advance.
回答1:
these env variables then used in configuration file you can find right config names by checking mail.php
in config
folder
You can change config values at run time by array to config helper.
See: https://laravel.com/docs/6.x/configuration#accessing-configuration-values
You need to find corresponding variables and set their value like for Laravel - 6
config([
'mail.driver' => 'smtp',
'mail.host' => 'smtp.mailgun.org',
'mail.port' => 587,
'mail.encryption' => 'tls',
'mail.username' => 'if-any',
'mail.password' => 'if-any',
]);
After that your new settings should be used.
来源:https://stackoverflow.com/questions/58461722/set-mail-driver-dynamically-from-database-for-different-email-in-notification