SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS on cakePHP - cakephp

I get the following error on my cakePHP2.7 project when I move the code to my new server. The code works fine on all my existing servers.
we are using aws SES as mail service.
We created a sample file as instructed by https://docs.aws.amazon.com/ses/latest/dg/send-using-smtp-programmatically.html and that also works fine.
Any help is appriciated
code for your reference
public $mailarr = array(
'host'=>'email-smtp.us-west-2.amazonaws.com',
'port' => 587,
'username' => 'XXXXXXXXXXXXXXX',
'password' => 'XXXXXXXXXXX',
'tls'=>true,
'returnPath'=>'xxx#xxx.com',
'transport' => 'Smtp',
'from' => array('xxx#xxx.com' => 'Alert!'),
'emailFormat' => 'html',
'timeout' => 300,
);
I have tried to add the below as part of my mailarr but the error still persists
'context' => array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
),
)

Related

check email with CakePHP IMAP Custom Datasource

I want to use my email on my server with CakePHP IMAP Custom Datasource.
In database.php I have:-
public $myCustomEmail = array(
'datasource' => 'ImapSource',
'server' => 'test.com',
'username' => 'info#test.com',
'password' => 'email password',
'port' => 143,
'ssl' => true,
'encoding' => 'UTF-8',
'error_handler' => 'php',
'auto_mark_as' => array(
'Seen',
// 'Answered',
// 'Flagged',
// 'Deleted',
// 'Draft',
),
);
When I set port to 143 or ssl to true I get this error:-
Error: Unable to get imap_thread after 4 retries. 'TLS/SSL failure for radindesign.com: SSL negotiation failed'
When ssl is set to false or I change the port I get this error:-
Unable to get imap_thread after 4 retries. 'Certificate failure for test.com: self signed certificate: /CN=linux10.centraldnserver.com/emailAddress=ssl#linux10.centraldnserver.com'
What's wrong with the IMAP authentication?
CakePHP IMAP Custom Datasource didnt help me i use from this :
// Configure your imap mailboxes
$mailboxes = array(
array(
'label' => 'Gmail',
'mailbox' => '{imap.gmail.com:993/imap/ssl}INBOX',
'username' => 'yourusername#gmail.com',
'password' => 'yourpassword'
),
array(
'label' => 'My Cpanel website',
'mailbox' => '{mail.yourdomain.com:143/notls}INBOX',
'username' => 'info+yourdomain.com',
'password' => 'yourpassword'
),
array(
'label' => 'Another mail account',
'mailbox' => '{mail.yourdomain.com:143/notls}INBOX',
'username' => 'info#yourdomain.com',
'password' => 'yourpassword'
)
);
//check inbox
$current_mailbox = array(
'label' => 'My Cpanel website',
'mailbox' => '{mail.test.com:143/notls}INBOX',
'username' => 'info#test.com',
'password' => '***'
);
// Open an IMAP stream to our mailbox
$stream = #imap_open($current_mailbox['mailbox'], $current_mailbox['username'], $current_mailbox['password']);
$emails = imap_search($stream, 'SINCE ' . date('d-M-Y', strtotime("-1 week")));
// If we've got some email IDs, sort them from new to old and show them
rsort($emails);
$i = 0;
$overview = array();
foreach ($emails as $email_id) {
// Fetch the email's overview and show subject, from and date.
$overview[$i] = imap_fetch_overview($stream, $email_id, 0);
$i++;
}
var_dump($overview);

Email not getting send by private mail server in cakephp

Hello Everyone,
I am trying to send email through cakephp framework,but unfortunately email are not getting delivered. But when i use social email service provider such as google, outlook and rediffmail e-mail gets delivered.
My SMTP port is 465. I am using below cakephp mail()function:
public $gmail = array(
'host' => 'ssl://smtp.techphant.com',
'port' => 465,
'username' => 'xyz#abc.com',
'password' => 'xxxxxx',
'transport' => 'smtp',
);
Also i have tried port number 2525 and 25 but to no avail.
Please let me know your suggestions.
Thanks in advance.
Try to send eamil with cake Email component not with mail() function.
$this->set(
'content',
'<h1>Hi </h1>
<p>Thanks for contact us. We will respond you soon</p>
'
);
$this->Email->smtpOptions = array(
'host' => 'ssl://smtp.techphant.com',
'port' => 465,
'username' => 'xyz#abc.com',
'password' => 'xxxxxx',
'timeout' => 30,
'client' => null
);
$this->Email->to = 'abc#gmail.com';
$this->Email->subject = 'Thanks for contact us';
$this->Email->from = 'no_reply#abc.com';
$this->Email->template = 'default';
$this->Email->sendAs = 'html';
$this->Email->send();
Thanks..!

symfony2 doctrine.dbal.connection_factory with ssl?

I connect to a remote database from within my symfony2 app with this code
$connectionFactory = $this->container->get('doctrine.dbal.connection_factory');
$conn = $connectionFactory->createConnection(array(
'driver' => 'pdo_mysql',
'user' => 'mattias',
'password' => 'fdfsdf',
'host' => 'fs1.rrtgy.se',
'dbname' => 'csmedia',
));
return $conn;
Is there a parameter I can set to do it using SSL?
The equivalent of something like this:
$link = mysql_connect("192.112.7.18","test","testpass",false,MYSQL_CLIENT_SSL)
You could try add to createConnection array 'driverOptions'
$conn = $connectionFactory->createConnection(array(
'driver' => 'pdo_mysql',
'user' => 'mattias',
'password' => 'fdfsdf',
'host' => 'fs1.rrtgy.se',
'dbname' => 'csmedia',
'driverOptions' => array(
PDO::MYSQL_ATTR_SSL_CA =>'/path/to/ssl-ca.pem'
),
));
More info about MYSQL SSL constants.
Notice, that some constants were added at php 5.3.7
However, SSL options are silently ignored in (at least) version 5.3.8: see the bug report.

CakePHP Config File

I was wondering is there a way i can set up the config where i can have two database entries that work when the environment is Local and when on Server.
I had come across a solution long time back on doing the switch through the code. Not able to find it now. How do you guys do it ?
I have a setup with local config files. I add the following lines at the bottom of app/config/core.php:
if(file_exists(ROOT.'/app/config/core.local.php')) {
include_once(ROOT.'/app/config/core.local.php');
}
In core.local.php I can override all the settings that differ on the local machine. The same goes for database.php.
I use a config class which does exactly that:
http://www.dereuromark.de/2010/08/17/development-vs-productive-setup
Recently I rewrote it for 2.0 as a plugin version.
It now takes care of test environments and cuts down the number of lines of configuration you will have to write:
http://www.dereuromark.de/2012/02/25/dynamic-database-switching/
I think it based on IP
at local environment IP is 127.0.0.1
and at live environment IP is never 127.0.0.1
My view
Thanks
check with the lib/Cake/Utility/String.php see the function named
public static function uuid()
cheers
Thanks again
This worked
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'username',
'password' => 'password',
'database' => 'database_name',
'prefix' => '',
//'encoding' => 'utf8',
);
public $live = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'db.HOST.net',
'login' => 'username',
'password' => 'password',
'database' => 'database_name',
'prefix' => '',
//'encoding' => 'utf8',
);
public function __construct(){
if (isset($_SERVER) && isset($_SERVER['SERVER_NAME'])) {
if (strpos($_SERVER['SERVER_NAME'], 'localhost') === false) {
$this->default = $this->live;
}
}
}
}

How Can I Read the DB Configuration Settings From a Cake Shell?

I would like to write a cake shell to do a nightly backup of my database using mysqldump. I could do this as a shell script, but if I can cram it into a CakePHP shell, then I will get the added benefit of it working across both the development and live server, if I can get it to automagically read my database config settings. I will cron the cake shell and have some peace-of-mind knowing that I have frequent backups of my DB.
In my shell I'm trying to build up a string which starts with "mysqldump --user=" and I'd like to get the username from app/config/database.php. How can I get at the data in database.php?
In cake 2.1 the format has changed to:
App::uses('ConnectionManager', 'Model');
$dataSource = ConnectionManager::getDataSource('default');
$username = $dataSource->config['login'];
The following snippet should do the trick:
App::import('Core', 'ConnectionManager');
$dataSource = ConnectionManager::getDataSource('default');
$username = $dataSource->config['login'];
In CakePHP 3.x the format has changed to -
use Cake\Datasource\ConnectionManager;
$source = ConnectionManager::get('default');
debug($source); #Debugging the result
Result :
object(Cake\Database\Connection) {
'config' => [
'password' => '*****',
'username' => '*****',
'host' => '*****',
'database' => '*****',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'quoteIdentifiers' => false,
'log' => false,
'url' => null,
'name' => 'remote'
],
'driver' => object(Cake\Database\Driver\Mysql) {
'connected' => false
},
'transactionLevel' => (int) 0,
'transactionStarted' => false,
'useSavePoints' => false,
'logQueries' => false,
'logger' => null
}
Get the Result :
debug($source->config()); #Accessing the result
Result :
[
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'username',
'password' => 'password',
'database' => 'database',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'quoteIdentifiers' => false,
'log' => false,
'url' => null,
'name' => 'remote'
]
Just for sharing.
For any cakephp project, if using php as cronjob or command line to do large data processing I would build a standalone php script without cakephp, the reason for doing this because cakephp is slow (e.g. read & process 100K records).
To make my life simple I put all my standalone scripts under app/Vendor/myscripts/ (e.g: app/Vendor/myscripts/process.php)
below also the basic code to make sure you use the same database settings in standalone script with cakephp (tested with MySQL)
require_once '/XYZ/app/Config/database.php';
$database = new DATABASE_CONFIG;
try{
$dblink = new PDO('mysql:host='.$database->default['host'].';dbname='.$database->default['database'], $database->default['login'], $database->default['password'], array(PDO::ATTR_PERSISTENT => false));
$dblink->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dblink->exec('SET CHARACTER SET '.$database->default['encoding']);
} catch (Exception $e) {
die('DB Error'. $e->getMessage());
}
Example in controller, Change multi DB for DataSources in CakePHP 2.5.x
App::uses('AppController', 'Controller');
class DemoController extends AppController {
public $uses = array('AppModel', 'GVA21', 'GVA01', 'GVA14', 'GVA24' );
public function test_dbs(){
$this->autoRender=false;
// Load ConnectManager
App::uses('ConnectionManager', 'Model');
// DataSource ['default']
$MDM = $this->GVA14->find('count');
echo "MDM.GVA14\n<br>";
debug($MDM);
// Get DataSource Config DB ['default'] and ['SRL']
$confDeafult = ConnectionManager::$config->default;
$confSrl = ConnectionManager::$config->SRL;
// Change DataSource ['SRL']
ConnectionManager::drop('default');
ConnectionManager::create('default',$confSrl); //<== Is permanet change Find All models Down
// $this->GVA01->setDataSource('SRL'); //<== Is temp change Find model
echo "SRL.GVA14\n<br>";
$SRL = $this->GVA14->find('count');
debug($SRL);
$SRL = $this->GVA01->find('count');
echo "SRL.GVA01\n<br>";
debug($SRL);
$SRL = $this->GVA21->find('count');
echo "SRL.GVA21\n<br>";
debug($SRL);
// Change to DataSource ['default']
debug(ConnectionManager::drop('default'));
ConnectionManager::create('default',$confDeafult); //<== Is permanet change Find All models Down
//$this->GVA01->setDataSource('default'); //<== Is temp change Find model
$MDM = $this->GVA01->find('count');
echo "MDM.GVA01\n<br>";
debug($MDM);
$MDM = $this->GVA21->find('count');
echo "MDM.GVA21\n<br>";
debug($MDM);
////FIN
exit('FIN');
}

Resources