Can't send reset password message in laravel 5 - laravel

Expected response code 250 but got code "530", with message "530-5.5.1 Authentication Required.
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME="username#gmail.com"
MAIL_PASSWORD="password"
MAIL_ENCRYPTION=tls
config/mail.php
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'username#gmail.com', 'name' => 'Name'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('username'),
'password' => env('password'),
'sendmail' => '/usr/sbin/sendmail -bs',

'username' => env('username')
'password' => env('password')
Should be:
'username' => env('MAIL_USERNAME')
'password' => env('MAIL_PASSWORD')

Related

How to change env configuration in Laravel controller?

I want to change env configuration from Controller, but this didnt work.
Controller
config(['MAIL_HOST' => 'smtp.sendgrid.net']);
config(['MAIL_PORT' => '25']);
config(['MAIL_USERNAME' => 'apikey']);
config(['MAIL_PASSWORD' => 'SG..']);
Mail::send(
'vendor.maileclipse.templates.news',
["content" => $content],
function ($message) use ($email) {
$message->to($email)->subject('Email');
}
);
}
.env
MAIL_DRIVER=smtp
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=xy#xy.com
MAIL_FROM_NAME="Test"
mail.php
You can set like below
config([
'mail.mailers.smtp.host' => '',
'mail.mailers.smtp.port' => ,
'mail.mailers.smtp.encryption' => '',
'mail.mailers.smtp.username' => '',
'mail.mailers.smtp.password' => '',
'mail.from.address' => ''
]
);
This will override from mail.php
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
Note:As infromed by #ceejayoz in comment .Remembe tt should be noted that this will only change it for that request. It will not change it for other requests, and will not update the .env file. –
Updated
config([
'mail.host' => '',
'mail.port' => ,
'mail.encryption' => '',
'mail.username' => '',
'mail.password' => '',
'mail.from.address' => ''
]
);
Use config file keys instead of .env variables, in your case config/mail.php
config(['mail.mailers.smtp.host' => 'smtp.sendgrid.net']);
config(['mail.mailers.smtp.port' => '25']);
config(['mail.mailers.smtp.username' => 'apikey']);
config(['mail.mailers.smtp.password' => 'SG...']);
Mail::send(
'vendor.maileclipse.templates.news',
["content" => $content],
function ($message) use ($email) {
$message->to($email)->subject('Email');
}
);
}

Laravel 6- Mail not sending from localhost

It showing me this error
Expected response code 250 but got code "530", with the message "530-5.7.0 Authentication Required. Learn more at 530 5.7.0 https://support.google.com/mail/?p=WantAuthError
while I have enabled two-factor authentication and generated an app password.
here is my .env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=myAppGeneratedPassword
MAIL_ENCRYPTION=tls
and here is my mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'myemail#gmail.com'),
'name' => env('MAIL_FROM_NAME', 'my_name'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('myemail#gmail.com'),
'password' => env('appPassword'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/mail'),
],
],
];
Please help me. I am trying for three days.
Can you try with this config
MAIL_PORT=465
MAIL_ENCRYPTION=ssl

Having trouble with using multiple database in laravel 5.7?

I'm having a problem with Laravel 5.7, it don't recognize a second database connection. Database 2 has a 'countries' table that Database 1 doesn't. But laravel insist with connect the Database 1. This is the error and actual code, please help! Thanks in advance
ERROR
SQLSTATE[42S02]: Base table or view not found: 1146 Table
'database_1.countries' doesn't exist (SQL: select * from countries)
MODEL
class Country extends Model {
use SoftDeletes;
protected $connection = 'mysql_2';
protected $table = 'countries';
protected $fillable = ['...'];
}
CONTROLLER / DEBUGGINB
class CountriesController extends Controller {
public function index(){
// neither works, this
$countries = DB::connection("mysql_2")->select('select * from countries');
// or this
$countries = Country::all();
dd($countries); --> both give ERROR
}
DATABASE.PHP
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'database_1'), //forge
'username' => env('DB_USERNAME', 'root'), // forge
'password' => env('DB_PASSWORD', ''),
.......
],
'mysql_2' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'database_2'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
.......
],
.ENV file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_1
DB_USERNAME=root
DB_PASSWORD=
DB_CONNECTION=mysql_2
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_2
DB_USERNAME=root
DB_PASSWORD=
and CACHE is updated:
php artisan config:cache
Configuration cache cleared!
Configuration cached successfully!
In your database.php file try to change
'mysql_2' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE2', 'database_2'), // THIS IS THE ONE THATS CHANGED
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
.......
],
.ENV FILE
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_1
DB_USERNAME=root
DB_PASSWORD=
DB_CONNECTION=mysql_2
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE2=database_2 // We change 'DB_Database' to 'DB_Database2'
DB_USERNAME=root
DB_PASSWORD=
Another process you can try -
.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_1
DB_USERNAME=root
DB_PASSWORD=
CUSTOM_DATABASE=database_2
CUSTOM_USERNAME=root
CUSTOM_PASSWORD=
database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
...................................
],
'custom' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('CUSTOM_DATABASE', 'forge'),
'username' => env('CUSTOM_USERNAME', 'forge'),
'password' => env('CUSTOM_PASSWORD', ''),
..........................................
],
YourModel.php
protected $connection = 'custom';
protected $fillable = [......];
If you use protected $connection in your model then you can use eloquent as usual. If so, then you can run your query like this -
$countries = Country::all();
And in your migration file -
public function up()
{
Schema::connection('custom')->create('your-table-name', function (Blueprint $table){
$table->bigIncrements('id');
...........................
$table->timestamps();
});
}

SQLSTATE[HY000] [2002] Connection refused (SQL: insert into users(name,email) values(mahmud,mahmudul#gamil.com))

I am using MySql Workbench for database. All doing well when I migrate my project.But when I want to insert data to the users table that time occurs this error "SQLSTATE[HY000] [2002] Connection refused (SQL: insert into users(name,email) values(mahmud,mahmudul#gamil.com))"
I am using windows, laravel 5.8,Homestead, MySql Workbench.
here some file:
.env:
enter image description here
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:KRf7nQxvFaheTWWPsflVa4KYZXR5Jwo5IvwXxogDJn4=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
database.php:
enter image description here
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '33060'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
]
web.php:
enter image description here
Route::get('/', function () {
return view('welcome');
});
Route::get('/insert',function(){
DB::insert("insert into users(name,email) values(?,?)",["mahmud","mahmudul#gamil.com"]);
});
page like:
enter image description here
please help me how to solve it.
thanks advance.
change .env and database.php:
.env:
replace
DB_HOST = 127.0.0.1
to
DB_HOST = localhost
and
database.php:
replace
'host' => env('DB_HOST', '127.0.0.1')
to
'host' => env('DB_HOST', 'localhost')
note: MySql Connection Hostname will be 127.0.0.1 and port will be 33060:
go to your config/database.php and paste below code
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => '/opt/lampp/var/mysql/mysql.sock',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
],

Laravel 5.8 Installation Error In database.php line 58: Undefined class constant 'MYSQL_ATTR_SSL_CA'

When I tried to install Laravel 5.8 it throws Error
In database.php line 58:
Undefined class constant 'MYSQL_ATTR_SSL_CA'
After this I have tried to run the application on server. It works fine sometimes. Sometimes it throws the same error. I couldn't run any commands on Artisan too. Why this happens and How to solve this?
New Laravel releases have this error. Look in config/database.php, you will see something like :
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]),
Secured Applications have an environment file that contains data for specific machine and software configurations like Database name and password, Email and password, value to tell if it's for development or production, etc.
Laravel loads them in constant accessible via global function env().
There is a file .env that contains those special values in Laravel. So open it and at the bottom of Database section, add your certificate path value:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog-db
DB_USERNAME=root
DB_PASSWORD=fakepass
MYSQL_ATTR_SSL_CA=relative/or/absolute/path/to/certificate.extension
Or if you're not planning to use SSL certificate for MySQL connection like most of us, then just comment it in config/database.php :
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
//'options' => array_filter([
// PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
//]),
Like it is currently at Laravel/Laravel master : https://github.com/laravel/laravel/blob/master/config/database.php
If you don't have MySQL extension, you should use:
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
in config/database.php instead of
'options' => array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]),
It's now included by default in Laravel 5.8 https://raw.githubusercontent.com/laravel/laravel/master/config/database.php (though it's probably not released yet).
So just update code with this above and you are good to go.

Resources