Laravel 6 never emails - php

I understand that Laravel no longer supports the mail() command that Wordpress and probably every other system use to simply send an email.
https://github.com/swiftmailer/swiftmailer/issues/866 shows that they now require smtp. Ok, but even if you sign up for a smtp service, and enter all the details as in:
https://www.bnmetrics.com/blog/sending-email-using-mailgun-laravel5
and php artisan config:cache ... repeatedly... with "smtp" or "mailgun" as the api, it never can even send the reset password built in to the Laravel user system.
Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required"
What's worse is that it never changes from that error message, even if I set
MAIL_HOST=smtp.example.com
it is never a different error message. Which makes me think something is seriously wrong with Laravel Mail (other than the fact it forbids using the standard mail/sendmail that just about any proper configured server can do). Is there a way I can composer install version 5.4.4 which apparently was the last working version according to here, or is there a better way to get Laravel mail working... with or without external service smtp?

If php artisan config:cache doesn't work and you are using e-mails in background using Laravel queues or Horizon, you should run:
php artisan queue:restart
or
php artisan horizon:terminate
to make sure workers will see config changes. Of course you should have Supervisor configured to run those queue workers after being stopped

Route::get('/sometesturl', function() {
var_dump(Config::get('mail'));
echo config('mail.port');
echo config('mail.driver');
echo config('mail.username');exit;
});
shows that there was no username even. Looking in the .env file I found that the added MAIL_ vars were getting overwritten by some defaults below!

Related

Laravel Debugbar Not Showing

I have a project with Laravel version 7.28. I run
composer require barryvdh/laravel-debugbar --dev,
After that I added Barryvdh\Debugbar\ServiceProvider::class to app/config.php under providers and added
'Debugbar' => Barryvdh\Debugbar\Facade::class
to app/config.php under aliases. Then I run
php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
Even though APP_DEBUG in .env is true and I terminated and rerun the app debugbar is not showing. Where did I make my mistake?
I checked the config/debugbar.php, I see the new key DEBUGBAR_ENABLED with default is false. Then add it to .env file: DEBUGBAR_ENABLED=true
Make sure you are running on right port. I had php backend (running on port 8000) and react frontend (running on port 3000) and I did everything you have described above but it never worked. The issue I had was that I was checking if the debugbar showed up on port 3000 (which it never did sadly). I went to check on port 8000 and the debugbar was sitting there the whole time.
I didn't end up using the php debugbar because I think it only works if your frontend code is written in php (though not 100% sure).
I ended up debugging using postman. It doesn't have all the functionalities that the debugbar offers but it is a great tool to use if you just want to do basic debugging.

php artisan serve command display error message

I am using php 7.3.2 on window 7. When I try to run php artisan serve, it shows this error on the webpage:
Whoops, looks like something went wrong.
Is it related to the message that I received when I want to migrate database, it says
Application In Production!
My error in laravel log shows
production.ERROR: RuntimeException: The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths. in C:\xampp\htdocs\Inventory\vendor\laravel\framework\src\Illuminate\Encryption\Encrypter.php:43
Following the error in your log file you seem to be missing your key attribute in your .env file. See this SO question for a solution.
To generate the secret key, run
$ php artisan key:generate
make sure to follow the official docs when installing Laravel.
Your laravel is running in production mode. If you are developing local, you should switch that for your local maschine.
To do so: In your .env set the APP_ENV to local (APP_ENV=local) and try again.
Now, you will see the full error message and you are able to handle it now.

Laravel Verify Email Address Issue

I have a problem with Laravel 5.7.22, I tried to activate the verification with the email and I get the message that:
A fresh verification link has been sent to your email address.
how it's properly working at least the part that send the emails with the verification link but when I click the generated link I get the following page:
I have tried to erase the project and reinstall it, and I also tried to generate the signature key with this command:
php artisan key:generate
that I have found in this other question, but that didn't work, I don't know what could be causing this issue.
I also tried to debug the the function hasValidSignature in the file UrlGenerator from Laravel, just because I read that it could help, but it doesn't make sense, I haven't event altered the middleware or something I'm just with the laravel routes that it generates by default.
The generated link looks something like this.
https://www.example.com/email/verify/1?expires=1548527438&signature=daebab97afbb2da6a0f37615bc3db7e59db9c59e704d185addcf88adf46e8f6d
I also have configured my .env file properly and the files under the config folder just for security.

Laravel 5.3 url() function alway print http://localhost

I have just switch to new version of laravel i.e. 5.3 for my new project.
Once I need to send registration mail to my portal customer, where registration mail contains account activation link where this mail is sent using Mail::queue.
I am generating that link using url("activate/$random_string");
and which always prints http://localhost/activate/$random_string_value
but what i wants is,
http://localhost/project/public/activate/$random_string_value
or
http://192.168.0.45/laravel/public/activate/$random_string_value
(above result i am getting till laravel 5.2)
i have set APP_URL value in .env as well and in config/app.php as well,
I have tried php artisan config:clear and php artisan config:cache
Can anybody help me to sort out this issue. I have one possible solution is to use env('APP_URL') to genrate same url.
I think your url need to update like:
url("activate/".$random_string);
Hope this work for you!

cURL error 60: SSL cert issue when sending email with artisan command

I have a weird issue going on with sending emails in Laravel.
I use Mailgun and can send emails fine when users register and everything like that.
I'm beginning to play around with scheduling commands and have created a custom artisan command to get some records and send some emails for these.
However when I run this command I get an error:
cURL error 60: SSL certificate problem: unable to get local issuer
certificate
I have set up a cacert.pem locally and linked this successfully in my php.ini file which is how I am able to send emails normally.
I don't understand why my command cannot send emails when I can send them just fine inside a controller.
This is the code I am using for the command:
$reminders = Reminder::where('utcReminderDate' , '<=', \Carbon\Carbon::now()->format('Y-m-d H:i'))->get();
foreach($reminders as $reminder)
{
Mail::send('emails.test', [], function($message) {
$message->to('me#example.com', 'Joe Bloggs');
$message->subject('A reminder for you');
});
}
I'm wanting to get all the reminders that need to be sent and loop through them to send them out.
When I run the command to test it via command line, it spits out the error above.
Any help getting the emails to send would be hugely appreciated. I use WAMP if that makes a difference.
You can either modify the vendor folder GuzzleHttp\Client change verify key to false from configureDefaults method as I did in my local machine
or
You can read this conversation in Laracasts and try downloading the .pem files in some of the comments.
Here are some links:
.pem File Download
After that you should edit your php.ini file accordingly:
curl.cainfo = "[pathtothisfile]\cacert.pem"
PS: I would just edit the vendor file, because it's much faster and not hard to realize.
Apparently PHP may load a different php.ini file when it is accessed from the CLI. See here.
Copying my php.ini file into C:\windows solved the issue.
Use this code:
$this->client = new GuzzleClient(['defaults' => [
'verify' => false
]]);
This works for me.

Categories