set mail driver dynamically from database for different email in notification

孤人 提交于 2020-01-06 06:56:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!