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

为君一笑 提交于 2020-01-06 19:25:01

问题


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). I cleared cache and restarted everything, I even deleted those files and laravel keeps sending emails with the deleted files configuration. What can i do?

.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:

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. It is ignoring the files updates.


回答1:


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.

We can tell Laravel to clear the cache and start afresh using this command:

php artisan config:clear




回答2:


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.



来源:https://stackoverflow.com/questions/33645663/env-and-mail-php-files-wont-update-laravel-5-1

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