php - 如何在使用 Laravel Controller 中发送邮件之前更改邮件配置?

标签 php email laravel

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

更新:A hack for saving the config at runtime.

关于php - 如何在使用 Laravel Controller 中发送邮件之前更改邮件配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23438342/

相关文章:

php - 使用 PostgreSQL 和 PHP 获取查询结果

asp.net-mvc - 发送电子邮件属于应用程序的表示层还是业务层?

html - 回复中的 HTML 电子邮件签名问题

php - 从 repo//PHP laravel 克隆项目后数据库出现问题

mysql - SQLSTATE[23000] : Integrity constraint violation: 1217

php - 是什么杀死了我的 PHP 进程,并留下这么多休眠的 mysql 连接?

php - 在 laravel 中添加两个整数

Swift 3 如何显示基于 MFMailComposeResult 电子邮件屏幕的确认屏幕

php - 如何解决 Laravel 中检查数据库值/变量可用性的问题

php - 无法解释的 PHP/MySQL 错误。代码可以在我的测试服务器上运行,但不能在永久服务器上运行