使用Laravel在控制器发送邮件之前如何更改邮件配置? [英] How to change mail configuration before sending a mail in the controller using Laravel?

查看:112
本文介绍了使用Laravel在控制器发送邮件之前如何更改邮件配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 4,我想在控制器中更改邮件配置(如驱动程序/主机/端口/ ...),因为我想在不同邮件配置的数据库中保存配置文件。这是使用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'));
});

我试图放一些东西,但没有工作

  $ message-> port('587'); 

感谢您的支持!



解决方案

您可以使用 Config :: set

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆