Laravel version 5.2.22
I have tried these to change the mailgun to smtp at runtime:
config(['MAIL_DRIVER' => 'SMTP']); //not work.
Config::set('MAIL_DRIVER', 'SMTP'); //not work.
Finally, I get these work:
Config::set('mail.driver', 'SMTP'); //works.
config(['mail.driver'=>'smtp']); //works.
I don't really know why have to change the MAIL_DRIVER to mail.driver.
Config::get('mail.driver'); //you can use this to check the config.
The answer Alex gave himself is the solution, it should be:
Config::set('mail.driver', 'SMTP');
The following does not work, as usually the env variable defining the mail driver is called MAIL_DRIVER, not the config variable. (See config/mail.php for the assignment of config('mail.driver')).
Config::set('MAIL_DRIVER', 'SMTP'); //config var MAIL_DRIVER does not exist yet / is not used.
Related
I use auth()->attempt() with remember me parameters.
if (auth()->attempt($credentials, $rememberMe)) {
When remember me is false, I can login normally,
but when remember me is true, I got an error.
RuntimeException
Cookie jar has not been set.
I tried to set .env
from SESSION_DRIVER=file
to SESSION_DRIVER=cookie
but still didn't work.
I'm using Laravel 7.24 and PHP 7.4.11
In my case I was using a custom Auth Guard that extended the built in SessionGuard. I had to set the cookie jar myself with
$this->setCookieJar(app('cookie'));
YMMV.
I fixed this problem for myself by putting 'driver' => 'session' under guards array in config/auth.php. But I was using different guard for admin panel authentication, so it might just be that you have this misconfigured as well.
I got the same error in my case when I used a custom guard. Calling setCookieJar, setDispatcher and setRequest on my guard solved the problem.
Look at this example
I'm using Laravel with Auth, Auth UI, Voyager admin panel, Telescope. Everything works fine untill I change APP_ENV=local to APP_ENV=production in .env file. When I change the .env file to production then I get the below error. screen shot of my issue is here.
Trying to get property 'name' of non-object
Basically I want to protect /telescope/*routes in production. But before doing that I am getting this error.
I read the same issue in github similar issue github link. I think the answer is present in the link but im unable to digest it as im a newbie.
Any help to fix this, and protecting telescope routes in production is much appreciated. I tried to create a Policy and give read permissions to the user via policy. But somehow im not able to fix it.
ok: its too easy - the only thing you have to do is:
php artisan make:policy -m User UserPolicy
thats it.
You can pass the array of email into the gate method in the TelescopeServiceProvider.php
Gate::define('viewTelescope', function ($user) {
return in_array($user->email, [
'username#domain.com'
]);
});
This will block everyone except the mentioned email of logged-in user.
I've been trying to email users a verification link using signed URLs in Laravel. It seems to work okay, but the link comes out incorrect when it is built using the URL facade.
public function toMail($notifiable)
{
$url = URL::signedRoute('confirm', ['user' => $this->user->id]);
return (new MailMessage)
->subject('Activate your email address')
->line('In order to use the application, please verify your email address.')
->action('Activate your account', $url)
->line('Thank you for using our application!');
}
In the email, the link looks like:
http://localhost/mydomain.com/confirm/14?signature=3ba4d86827717440f70a3b2f60c913b6e84d550cb9fce8de04a8ba359833ac7c
The "localhost" part should not be there. However, if I manually delete it in the URL bar, I believe the signed URL things I manipulated the URL and gives me a 401 error. I am running on a localhost environment but I use Laragon's auto virtual host so that I can still run it with a domain.
Any suggestions?
Sometimes if you are working in virtual environments or docker container, just setting APP_URL won't work. Try the following steps.
Step 1: Set your domain in your .env file. (Don't forget the double quotes)
APP_URL="http://yourdomain.com"
Step 2: Add following line before generating your signed route
URL::forceRootUrl(\config('app.url'));
Step 3: (Optional) Add following line, if you want to force https scheme
URL::forceScheme('https');
Change:
APP_URL=example.com
To:
APP_URL=http://example.com
I guess not specifying "http://" makes it append localhost to the front. Hope this helps someone!
Site use port 8080 on new server.
I need "site.com" => "site.com:8080"
How change base url in laravel for correct including css/js and redirects?
Ok, we tried many things.
It seems it's a bug or something. They have it since Laravel 4 and do not want to fix it:
https://github.com/laravel/framework/issues/1833
The only solutions I see here are:
1. To use standard port.
2. To generate URLs manually. For example:
// in controller
$baseUrl = 'http://'.$_SERVER['HTTP_HOST'].'/';
// in template
<link hre="{{ $baseUrl.'css/myStyleSheet.css' }}" ....>
Or you could set this variable in your top layout, so all inherited views have it.
I ended up adding the following line to boot() function of AppServiceProvider.php :
URL::forceRootUrl(env('APP_URL'));
You can also hardcode it there, but this way it uses the settings from .env file.
Warning: if the APP_URL is https, then I also needed to add the following line, or otherwise it would alter it to http (weird):
URL::forceScheme('https');
I'm trying to send emails from Joomla! 1.5.9, but keep getting this error message: PHPMAILER_RECIPIENTS_FAILEDrecipient_name<recipient_email>
A few more facts:
It's a WAMP server (joomla 1.5.9, PHP 5.2.8)
Validation emails are sent with no problem at all
Joomla! is set to use SMTP
The IIS SMTP service is used (though I'm not 100% sure about it's configuration)
The diagnostics tool smtpdiag shows no problem when checking the sender/recipient
Any ideas?
Thanks,
Omer.
Perhaps this has already been answered before # Joomla forums itself.
http://forum.joomla.org/viewtopic.php?f=431&t=272547
I tried many of the solutions given in the link Sukumar provided but none of them worked.
Then I tried to use PHP mail function instead of SMTP and it worked :)
Change the following line in configuration.php in the root folder
var $mailer = 'smtp';
to
var $mailer = 'PHP mail';