简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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