简体   繁体   English

.env和mail.php文件不会更新-Laravel 5.1

[英].env and mail.php files won't update - Laravel 5.1

I started a project a few months ago and set the configuration to send mail, everything works great. 我几个月前开始了一个项目,并设置了配置以发送邮件,一切正常。 But now i want to change the sender email address, so i changed the configuration in the .env and mail.php files, but laravel just ignored the updates (still uses the old configuration to send mail). 但是现在我想更改发件人的电子邮件地址,因此我更改了.env和mail.php文件中的配置,但是laravel只是忽略了更新(仍使用旧配置发送邮件)。 I cleared cache and restarted everything, I even deleted those files and laravel keeps sending emails with the deleted files configuration. 我清除了缓存并重新启动了所有内容,甚至删除了这些文件,并且laravel继续使用已删除的文件配置发送电子邮件。 What can i do? 我能做什么?

.env: .env:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=someaddress@gmail.com
MAIL_PASSWORD=******
MAIL_ENCRYPTION=null

config/mail.php: config / mail.php:

return [

    'driver' => 'smtp',
    'host' => 'smtp.gmail.com',
    'port' => 587,
    'from' => ['address' => 'someaddress@gmail.com', 'name' => 'Some Name'],
    'encryption' => 'tls',
    'username' => 'someaddress@gmail.com',
    'password' => '******',
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,

];

Controller: 控制器:

Mail::send('emails.devolucion', ['datos' => $diet], function ($message) use ($diet){
        $message->to($diet['correo'], $diet['nombre'])->subject('Devolución');
});

I used to have another address instead of "someaddress@gmail.com", and laravel keeps using that old email address instead of the new one. 我曾经有另一个地址,而不是“ someaddress@gmail.com”,而laravel一直使用那个旧的电子邮件地址而不是新的电子邮件地址。 It is ignoring the files updates. 它忽略了文件更新。

It sounds like your config files are being cached, and that Laravel is then reading them from the cache which is why your updates aren't being reflected. 听起来您的配置文件正在缓存中,然后Laravel从缓存中读取它们,这就是为什么未反映您的更新的原因。

We can tell Laravel to clear the cache and start afresh using this command: 我们可以告诉Laravel使用以下命令清除缓存并重新开始:

php artisan config:clear

Laravel Mail Laravel Mail

Comment out the from address inside the mail function (if you have one), then the value from the configuration will be automatically taken 注释掉邮件功能内部的发件人地址(如果有的话),那么配置中的值将被自动获取

Mail::send('emails.newuser', $mailData,
  function( $message) {
  //$message->from('feedback@example.com', 'No Reply');
  $message->to('user@example.com');
  $message->subject('Mail Subject');
});

Hope this is helpful. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM