使用Laravel在控制器发送邮件之前如何更改邮件配置? [英] How to change mail configuration before sending a mail in the controller using Laravel?
问题描述
Mail :: send(
'emails) Responsable.password_lost',
array(),
function($ message)use($ responsable){
$ message-> to($ responsable-> email,$ responsable-> ; getName());
$ message-> subject(Lang :: get('email.password_lost'));
});
我试图放一些东西,但没有工作
$ message-> port('587');
感谢您的支持!
您可以使用 Config :: set $ c即时设置/更改任何配置$ c>:
Config :: set('key','value');
所以,设置/更改 mail.php
你可以尝试这样:
Config :: set('mail.port',587); //默认
注意:配置值仅在
当前请求中设置运行时设置,不会被转移到后续请求。 阅读更多。
更新:将配置保存在运行时。
I'm using Laravel 4, I would like to change the mail configuration (like driver/host/port/...) in the controller as I would like to save profiles in databases with different mail configuration. This is the basic send mail using configuration from config/mail.php
Mail::send(
'emails.responsable.password_lost',
array(),
function($message) use ($responsable){
$message->to($responsable->email, $responsable->getName());
$message->subject(Lang::get('email.password_lost'));
});
I've tried to put something like but it didn't work
$message->port('587');
Thanks for your support!
Jean
You can set/change any configuration on the fly using Config::set
:
Config::set('key', 'value');
So, to set/change the port in mail.php
you may try this:
Config::set('mail.port', 587); // default
Note: Configuration values that are set at run-time are only set for the current request, and will not be carried over to subsequent requests. Read more.
Update: A hack for saving the config at runtime.
这篇关于使用Laravel在控制器发送邮件之前如何更改邮件配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!