I7m developing a website using CakePHP 3.7. I'm working on localhost and would like to send an email from localhost to gmail, but getting error - cakephp

I am able to send an email from xampp (Mecury) localhost to localhost. But when I try to send an email from Gmail to the localhost I am not being able to do that.
Our main purpose is to send email from Gmail account to the localhost. How can I do that, Any help can be appreciated.
This is the code in my app.php file:
'EmailTransport' => [
'default' => [
//'className' => MailTransport::class,
'className' => 'Smtp',
/*
* The following keys are used in SMTP transports:
*/
'host' => 'smtp.gmail.com',
'port' => 587,
'timeout' => 30,
'username' => 'my#gmail.com',
'password' => 'secret',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
'Email' => [
'default' => [
'transport' => 'default',
'from' => ['demotest#localhost.com' => 'demotest'],
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],

Related

SMTP Time out error - Send email from localhost

I tried to send email using Google SMTP from localhost, but I keep getting the SMTP time out. error.
This is my config:
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'tls://smtp.gmail.com',
'port' => 587,
'username' => 'xxxxx#gmail.com',
'password' => 'xxxxxsecret',
'log' => true,
'tls' => true,
'domain' => 'localhost',
],
],
I'm running my app on Wampp server.
Please help me, thank you in advanced!
Using mailtrap, you can test this locally. If this works, then most likely the configuration is incorrect or the email isn't being sent through google mail.
https://mailtrap.io - create account and use for free.
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
'host' => 'smtp.mailtrap.io',
'port' => 2525,
'timeout' => 30,
'username' => 'YOUR_USERNAME',
'password' => 'YOUR_PASSWORD',
'client' => null,
'tls' => true,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
You can also change the port from 587 to 465 and check. Allow Google to trust your local email server.

How to use multiple db2 databases in Laravel

Currently i use the package cooperl/laravel-db2 for the database connection. For my project, i should to toggle schema database.
I try this in db2.php :
'connections' => [
'ibmi_1' => [
...
'host' => '***********',
'username' => '***********',
'password' => '***********',
'database' => 'database',
'prefix' => '',
'schema' => 'schema_1',
'port' => *****,
'date_format' => 'Y-m-d H:i:s',
...
],
'ibmi_2' => [
...
'host' => '***********',
'username' => '***********',
'password' => '***********',
'database' => 'database',
'prefix' => '',
'schema' => 'schema_2',
'port' => *****,
...
],
And this in .env
DB_CONNECTION=ibmi_1
DB_HOST=
DB_PORT=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
DB_CONNECTION=ibmi_2
DB_HOST=
DB_PORT=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
But when i try in tinker
DB::connection('ibmi_2')
I have this error
InvalidArgumentException with message 'Database connection [ibmi_2] not configured.'
What is wrong ?
The problem was that the database configuration wasn't in bootstrap/cache/config.php.

Unsupported driver [ ] in laravel

i am facing issue of unsupported driver while hitting my API i have following configurations in my config/database.php
'mysql' => [
'driver' => env('DB_CONNECTION'),
'host' => env('DB_HOST'),
'port' => env('DB_PORT'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
// 'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
and my env file
DB_CONNECTION=mysql
DB_HOST=someURLsomeUrl
DB_PORT=3306
DB_DATABASE=ovadahealth_dev
DB_USERNAME=ovadahealth_user
DB_PASSWORD=password
I have spent an hours in this issue and i cant find out where is the issue when i hit my api in postman it says:
{
"status": false,
"message": "Unsupported driver []"
}
Here your help will be highly appreciated!
use php artisan config:clear to clear your configuration.

Sending email from gmail using CakePHP3, Connection refused

I am having a problem with configuration with CakePHP3 for sending email from my Gmail account. I always get an error Connection refused. I don't know where the problem is. So I hope anyone here has any knowledge about sending emails from my Gmail account.
EDIT: I am using GoDaddy hosting server
Here are my configurations.
'gmail' => [
'host' => '(ssl://)smtp.gmail.com',
'port' => 465,
'username' => 'MyGmail#gmail.com',
'password' => 'pass',
'className' => 'Smtp',
'tls' => true
],
'Email' => [
'gmail' => [
'transport' => 'gmail',
'from' => 'myGmail#gmail.com',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],
First update email config in CakePHP
Your Updated config/app.php file should be as :
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'username#domain.com',
'password' => 'your_password',
],
],
and now use the mail function of CakePHP Email Function.

Error connecting to Cloud SQL if using Self-signed certificate by Google

When trying to connect to Cloud SQL using a Google's self-generated SSL certificate we get the following error:
Connection to database could not be established: SQLSTATE [HY000] [2002]
Change file in: config/app.php
...
...
/**
* The test connection is used during the test suite.
*/
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'xx.xxx.xxx.xxx',
//'port' => 'non_standard_port_number',
'username' => 'user_name_x',
'password' => 'pass_x',
'database' => 'bd_name_x',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'quoteIdentifiers' => false,
'log' => false,
'flags' => [
PDO::MYSQL_ATTR_SSL_KEY => CONFIG.'client-key.pem',
PDO::MYSQL_ATTR_SSL_CERT => CONFIG.'client-cert.pem',
PDO::MYSQL_ATTR_SSL_CA => CONFIG.'server-ca.pem',
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
],
//'ssl_key' => CONFIG.'client-key.pem',
//'ssl_cert' => CONFIG.'client-cert.pem',
//'ssl_ca' => CONFIG.'server-ca.pem',
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
],
],
...
...
Example Test PHP Pure + PDO + SSL Self signed by google:
$pdo = new PDO('mysql:host=xxx.xxx.xxx.xxx;dbname=db_name_x', 'user_name_x', 'pass_x', array(
PDO::MYSQL_ATTR_SSL_KEY => '/path/full/client-key.pem',
PDO::MYSQL_ATTR_SSL_CERT => '/path/full/client-cert.pem',
PDO::MYSQL_ATTR_SSL_CA => '/path/full/server-ca.pem',
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
)
);
$statement = $pdo->query("SHOW TABLES;");
var_dump($statement);
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo json_encode($row);
exit();

Resources