2

I use laravel 5.3 and I change env on the staging server on the forge (https://forge.laravel.com)

I change like this :

#MAIL_HOST=smtp.gmail.com
#MAIL_PORT=587
#MAIL_USERNAME=mygmail@gmail.com
#MAIL_PASSWORD=secret
#MAIL_ENCRYPTION=tls

MAIL_HOST=mail.myshop.id
MAIL_PORT=587
MAIL_USERNAME=contact@myshop.id
MAIL_PASSWORD=secret
MAIL_ENCRYPTION=tls

If I try send mail in my system, the email sender is mygmail@gmail.com

Should the email sender contact@myshop.id

How can I solve this problem?

miken32
  • 42,008
  • 16
  • 111
  • 154
moses toh
  • 12,344
  • 71
  • 243
  • 443
  • Is your settings cached? If so try refresh settings cache with `php artisan config:cache` command. – Makashov Nurbol Dec 07 '17 at 04:08
  • @Makashov Nurbol, run `php artisan config:cache` if on localhost. In staging server(forge laravel) seems unnecessary. Yesterday when I changed env, it worked. I do not know why today is not working – moses toh Dec 07 '17 at 04:33
  • Does this answer your question? [Laravel not reading changes to .env file](https://stackoverflow.com/questions/34420761/laravel-not-reading-changes-to-env-file) – miken32 Aug 04 '23 at 17:48

6 Answers6

17

I use laravel 5.7 running with supervisor to handle the queues. Following steps helped me out:

php artisan config:cache

This command refreshes the config file in the cache. you can check it in bootstrap/cache/config.php and look for the 'mail' array.

php artisan queue:restart

Tell the queue to use the new configs and restart the supervisor.

If the above commands didn't solve the problem, these commands might help:

php artisan cache:clear

sudo supervisorctl restart all

sudo nginx -s reload

Also, you can set your from address. Just take a look at config/mail.php file.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=xxxxxxxxx
MAIL_PASSWORD=xxxxxxxxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@youremail.com
MAIL_FROM_NAME=yourname
Community
  • 1
  • 1
Fred Lai
  • 1,131
  • 10
  • 21
  • `php artisan queue:restart` did it for me, laravel 7 – gattsbr Apr 08 '20 at 15:56
  • 1
    @gattsbr yes, you are right. `php artisan queue:restart` should work on all the versions as it gracefully restarts all of the workers. Often times, no need to do `sudo supervisorctl restart all` because it's doing the same thing as `queue:restart`. – Fred Lai Apr 12 '20 at 04:13
1

On Laravel 5.1 php artisan config:clear did not work. Instead, I needed to run

php artisan config:cache

karel
  • 468
  • 5
  • 14
0

I’m hesitating between two possible issues.. First possibility: That might be because of the use of a cache by your artisan server if you are running your app with it. So try to stop your artisan server and restart it Second one: the email is set somewhere else. So check your config files (in config/ directory).

Hope this will help

Medteck
  • 496
  • 4
  • 12
0

I know this is an old question, but I was in the same situation and found something that worked for me

php artisan config:clear

Maybe can help someone else landing here.

Take
  • 121
  • 1
  • 5
0
php artisan config:clear;

to call this from a route (for shared hosting without SSH for example)

Artisan::call('config:cache');
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
mike rigley
  • 11
  • 1
  • 4
-1

MAIL CONFIGURATION on your ENV doesn't mean that will be your sender email to be display on the recipient that will just be the credentials to be used in order the email service work, if you want you may configure it using the mail.php configuration file in config folder or directly to the Mail function of laravel.

$mail->from(YOUR_EMAIL_ADDRESS,YOUR_DISPLAY_NAME);
Kenneth Sunday
  • 865
  • 7
  • 14
  • I try on the localhost, it works. It does not works on the staging server – moses toh Dec 07 '17 at 05:15
  • The correct answer as Laravel recommends is to set the value in the .env file, specifically the MAIL_FROM_ADDRESS key. So the MAIL CONFIGURATION on the env will indeed work. – Miki Maine Amdu Apr 20 '20 at 16:07