0

I have already set my email configuration on .env file but when i check from tinker is shows null value.

enter image description here

here is my env config

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=465
MAIL_USERNAME=c57xxxx07f1
MAIL_PASSWORD=44****02fae
MAIL_ENCRYPTION=tls

i cant send email any solution for this ??

  • what version of Laravel are you using? did you alter the `config/mail.php` file? – lagbox Nov 18 '19 at 06:20
  • 5.8 no i didn't alter anything – Muhammad Saad Nov 18 '19 at 06:24
  • i guess this wasn't a fresh 5.8 install and this was upgraded from previous versions? just trying to confirm why you are missing configuration keys that should be in the mail config for that version – lagbox Nov 18 '19 at 06:27

3 Answers3

1

You need to clear the cache after changes in your env file. Otherwise, your changes are not updated. So whenever you made changes need to clear cache and then after use tinker.

php artisan config:clear

php artisan tinker

config('mail')
Amit Senjaliya
  • 2,867
  • 1
  • 10
  • 24
1

after using config('email') If you not get your .env email configuration then

php artisan config:cache

Then

php artisan tinker
config('mail')

get your result

albus_severus
  • 3,626
  • 1
  • 13
  • 25
0

Try to find your config/mail.php

And put your env key inside.

env('MAIL_HOST', 'smtp.mailgun.org')

First argument is your env key, second arg is the default value.

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    ...

And clear config cache:

php artisan config:clear
php artisan optimize
TsaiKoga
  • 12,914
  • 2
  • 19
  • 28
  • @MuhammadSaad I think you env not working. Try to type ```ENV('MAIL_PORT')``` in tinker. – TsaiKoga Nov 18 '19 at 06:27
  • >>> ENV('MAIL_PORT') => "465" – Muhammad Saad Nov 18 '19 at 06:28
  • Do you cache config before you set them? – TsaiKoga Nov 18 '19 at 06:30
  • its show everything in tinker when when i run config('mail') its show nothing – Muhammad Saad Nov 18 '19 at 06:30
  • @TsaiKoga in the screenshot they seem to be clearing the config cache before using tinker .. and `cache:clear` is for the cache store, not config cache or view cache or route cache – lagbox Nov 18 '19 at 06:31
  • ya whenever i change config in my env file i clear my cache,config etc each and everything – Muhammad Saad Nov 18 '19 at 06:31
  • @MuhammadSaad what about use double quotaion mark. like ```MAIL_PORT="465"``` – TsaiKoga Nov 18 '19 at 06:34
  • i copied directly from terminal that y its showing in double quotation. – Muhammad Saad Nov 18 '19 at 06:35
  • i think that config('mail') is not picking the key value from env file thats y its showing null values in all column – Muhammad Saad Nov 18 '19 at 06:36
  • @MuhammadSaad https://stackoverflow.com/questions/34420761/laravel-5-2-not-reading-env-file – TsaiKoga Nov 18 '19 at 06:37
  • @MuhammadSaad I have also said in my answer clear cache first. – Amit Senjaliya Nov 18 '19 at 06:40
  • @lagbox `cache:clear` do clear config cache. You can try it. It will clear the file in `boostrap/cache/config.php` – TsaiKoga Nov 18 '19 at 06:42
  • no, it does not `cache:clear` is for clearing the application cache/cache store .. `config:clear` clears the cached config file – lagbox Nov 18 '19 at 06:45
  • it wont clear the config cache ... it is for flushing the cache store – lagbox Nov 18 '19 at 06:48
  • @lagbox When I run `php artisan config:cache`, the `config.php` will generated in `bootstrap/cache`, and `php artisan cache:clear`, this file will be deleted. – TsaiKoga Nov 18 '19 at 06:54
  • it does not delete the config cache. https://github.com/laravel/framework/blob/5.8/src/Illuminate/Cache/Console/ClearCommand.php that is the source code ... there is nothing in there that would delete any files in `bootstrap/cache` – lagbox Nov 18 '19 at 07:34
  • 1
    @lagbox Sorry. My mistake. I run `php artisan config:clear` instead of `php artisan cache:clear` in my terminal. You are right. There are no `bootstrap/cache` in that source code. – TsaiKoga Nov 18 '19 at 09:33
  • its okay, just for some strange reason people only on Stack Overflow think that `cache:clear` is some magical command – lagbox Nov 18 '19 at 09:35