Laravel: Configuring default mail host - laravel

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

Related

Mailhog Setup in Laravel 6.x

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.

(Laravel) Trying to send email when a user is signed up, have a connection error

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

Why my email sender does not update when I change the settings in env laravel on staging server?

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

Whoops, looks like something went wrong. on server

I uploaded all laravel project on server, its working fine on local but getting error on server, even database configuration and key is configured in env. file. even i renamed .env.example file as .env too but got same error.
Error is
"Whoops, looks like something went wrong."
my error log is here:
[2017-11-06 15:19:07] local.ERROR: exception 'RuntimeException' with
message 'The only supported ciphers are AES-128-CBC and AES-256-CBC
with the correct key lengths.' in
/home/rndspot5/public_html/dev/lea/vendor/laravel/framework/‌​src/Illuminate/Encry‌​ption/Encrypter.php:‌​43
Judging from your error, you need to run php artisan key:generate this will update your key of which in turn will rectify your error.
You will need to either SSH into your public_html folder if you have host permission to do so. Alternatively, you can ask your host provider to either:
Grant you SSH access
Perform this action for you.
You can then run: php artisan config:clear once the new key has been generated.
If you are on shared hosting you can use these steps
Open your .env file, copy APP_KEY to somewhere else as a backup
Run php artisan key:generate from console
Copy the new APP_KEY and upload it to the .env file on your (shared) server
Move the old key back to development
I resolved this issue, by adding web app url in .env and Config/App.php and now its working :) thanks all of you for sharing such a value able knowledge that will help me, may be later.

Laravel 5.4 Token Mismatch Exception on live server

I am facing Token mismatch exception in Laravel 5.4 on live server. On my local machine running Windows XAMPP, the application works fine. When I deployed it to live machine running CENTOS 7 and LAMP stack, I see a redirecting to myhostname.com/login at the top left corner of the browser and then lands on an error page showing:
token mismatch exception on line 68 of VerifyCsrfToken.php.
I had this same problem and what i did was:
First in your .env file remove: SESSION_DOMAIN
And in set session driver like: SESSION_DRIVER=file (if your want it to save to a file)
then do: php artisan cache:clear
then `php artisan config:clear
that worked for me.
Try to clear config cache on the server with :
artisan cache:config
You will need to clear config cache also if you edited config/app.php for some reason.
In addition there is an other possible reason : you copied not only the application but also the cache/session files when you deployed your application to production. Basically everything in the storage folder should be ignored on deployment.
Run this command
php artisan config:clear
Verify .env file
delete current .env file and create new .env file from .env.example
verify that config/session.php has is correct or not modified.
You can check the file permission as well of storage directory

Resources