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.
Related
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.
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',
],
],
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.
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();
My MySQL connection details are different for both my local connection and my deployed live hosted. I am using CakePHP 3
At the moment I have to keep changing the default datasource which is not really the best way to do it.
I have not added two datasources but I am not sure how to switch between them?
'Datasources' => [
'development' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => '127.0.0.1',
'port' => '8889',
'username' => 'root',
'password' => 'root',
'database' => 'local',
],
'deployment' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'username',
'password' => 'password',
'database' => 'live_database',
],
In boostrap or in App Controller, paste this
if(Configure::read('debug')){
ConnectionManager::config('deployment');
}
this change the default config of database when the debug is true.