Using Laravel 6.0, I have configured my .env file to utilize Mailhog in my local environment as explained in the Docs.
MAIL_DRIVER=smtp
MAIL_HOST=0.0.0.0
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
I can go to http://localhost:8025 and see the Mailhog interface.
However, when I try to send an email either through a controller method or on my local file system via php artisan tinker, no mail gets through.
The only time mail does get through to Mailhog is if I vagrant ssh and run php artisan tinker from inside of there.
This is all I'm trying to send: Mail::raw('FROM HOME CONTROLLER', function ($message){ $message->to('contact#contact.com');});
I have tried using MAIL_HOST=localhost, 127.0.0.1, 192.168.10.10. I've tried different user/pass combos (testuser, password, testpass, etc), to no avail.
The reason it was not going through was a simple route misconfiguration (accessing the wrong route in my web.php router file).
Still unable to get it working via php artisan tinker locally though, which I would imagine has to do with PHP mail not actually being present without being inside of the vagrant instance.
Related
I have APP_URL env variable set to domainname.com and I have url set to the same domain in config file as well. route('route.name') in artisan tinker returns the proper domain. yet when used in the applicaiton code, it returns localhost. Any thoughts from you would be appreciated.
Edit: My environment is Github codespaces
Try running php artisan optimize:clear command to clear cache,
routes etc all in one go.
If you have separate frontend then change it there as well to hit the
right backend with your provided domain name.
Restart your docker containers if you are using Docker.
I have module sending email to the administrator of the website.
Scenario: if the user done fill up all the text box then he / she submit it, automatically the administrator of website determine that there is new message.
The problem is, the administrator email look like this.
administrator#xxxxxxx.ca it gives error when the user click.
ENV FILE:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.xxxxxx.ca
MAIL_PORT=587
MAIL_USERNAME=xxxxxx.xxxxx#xxxxx.ca
MAIL_PASSWORD=xxxxxxxxxx
MAIL_ENCRYPTION=tls
Connection could not be established with host smtp.xxxxxxx.ca [php_network_getaddresses: getaddrinfo failed: No such host is known. #0]
How to configure the host #gmail.com to host xxxxxx.ca
This problem occurs when some changes have been made to files, specifically in .env file
Clear cache using artisan command
php artisan config:clear
Clear config
php artisan cache:clear
Restart your server
sudo service apache2 restart
More: Try clearing browsers cache & cookies. Hope that works
I'm trying to test laravel's mailing with mailtrap I set up all the requirements in.env folder but when I sign up, it throwes following error:
Connection could not be established with host smtp.mailtrap.io [php_network_getaddresses: getaddrinfo failed: A non-recoverable error occurred during a database lookup. #0]
The mailing is done with event listener. so it lets me sign up
Laravel 5.4
Wamp64 server
This is my code in .env for connecting mailtrap:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=**************
MAIL_PASSWORD=**************
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=noreplay#smthing.com
MAIL_FROM_NAME="smthing"
I'm still looking for a solution.
Here is the solution I found. Anybody with the same issue should run following commands:
composer update
php artisan config:clear
php artisan cache:clear
composer dumpautoload
If this still doesn't work, than you should try deleting bootstrap/config files. But be careful, take a copy of thw folder before you do that, in case they don't generate automatically. The issue causung this error is that. Laravel does not compile the applicate, each time you run it, so the when you create providers or composers, Laravel does not promise it will compile it. Which mean a code qhoch doesn't work now, might work tomorrow, because it is running from catch. So clear catch, update composer, install composer, do everything that refreshes code. It will eventually work
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?
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
On Laravel 5.1 php artisan config:clear did not work. Instead, I needed to run
php artisan config:cache
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
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.
php artisan config:clear;
to call this from a route (for shared hosting without SSH for example)
Artisan::call('config:cache');
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);
I changed MAIL_DRIVER in .env file of production server like that:
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAILGUN_DOMAIN=mg.xx.com
MAILGUN_SECRET=key-xx
MAIL_ENCRYPTION=null
I run these commands also:
php artisan config:clear
php artisan config:cache
However, they did not change MAIL_DRIVER. Server continues to send mail via old MAIL_DRIVER. I got from controller env("MAIL_DRIVER"), and it gets nothing (NULL).
How can I solve this problem.
You will need to restart your server and/or just re run php artisan serve on local dev.