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
Related
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');
}
);
}
This is my web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/register',[App\Http\Controllers\AdminController::class, 'ShowRegister']);
Route::post('/register',[App\Http\Controllers\AdminController::class, 'Register'])->name('register');
.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=project
DB_USERNAME=root
DB_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', 'project'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),
'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'),
]) : [],
],
when i try to submit form of register it gives me errors as
Illuminate\Database\QueryException SQLSTATE[HY000] [2002] No such file
or directory (SQL: select count(*) as aggregate from admins where
email = hello#gmail.com) http://127.0.0.1:8004/register
I searched about it too and came to solution that adding unix_socket fixed issue but unfortunately it doesnot help me either !!
what can be issue here ? Help me please !!
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();
});
}
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,
],
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')