imap_open failed in my server but works in local - php

$mailboxes =
array(
'label' => 'Mail',
'mailbox' => '{mail.example.com:143/novalidate-cert}INBOX',
'username' => "myadress#mail.com",
'password' => "mypassword"
);
imap_open($mailboxes['mailbox'], $mailboxes['username'], $mailboxes['password'])
I have caught this error when I use imap_last_error() :
"Connection failed to mail.example.com,143: Connection timed out"
But when I have tried it in localhost (Wampserveur), everything works fine.
Note: extension=php_imap.dll is enable on my serveur.

Related

sqlsrv_connect works fine in php but fails in laravel on the same server(AWS EC2 Instance)

I am trying to connect MSSQL database as my second database in Laravel, In the core PHP file It works fine but when I try to connect in the laravel It throws an error.
Here is my .env
MSSQL_CONNECTION=sqlsrv
MSSQL_DATABASE_URL='/EC2AMAZ-61LPEGK\SQLEXPRESS'
MSSQL_HOST=XX.XX.X.XXX
MSSQL_PORT=1433
MSSQL_DATABASE="/dbcrm"
MSSQL_USERNAME="sauser"
MSSQL_PASSWORD='dbpassword123'
MSSQL_TRUSTSERVER='yes'
MSSQL_ENCRYPT=False
MSSQL_STRICT=false
and here is my laravel database config:
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('MSSQL_DATABASE', '/EC2AMAZ-61LPEGK\SQLEXPRESS'),
'host' => env('MSSQL_HOST', 'XX.XX.X.XXX'),
'port' => env('MSSQL_HOSTDB_PORT', '1433'), //I had tried null
'database' => env('MSSQL_DATABASE', '/dbcrm'), //tried without '/'
'username' => env('MSSQL_USERNAME', 'sauser'),
'password' => env('MSSQL_PASSWORD', 'dbpassword123'),
'trust_server_certificate' => env('MSSQL_TRUSTSERVER', 'yes'), //tried 'no'
'encrypt' => env('MSSQL_ENCRYPT', False), //tried true
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
Here is the PHP file code which works fine and connect the database as well as execute the query,
$host ="XX.XX.X.XXX";
$username ="sauser";
$password ="dbpassword123";
$database ="dbcrm";
$params = [
"UID" => $username,
"PWD" => $password,
"Database" => $database,
"TrustServerCertificate" => "yes",
];
if(sqlsrv_connect($host, $params)) {
echo "connected..";
} else {
echo "Connection could not be established.<br />";
echo "<pre>";
die( print_r( sqlsrv_errors(), true));
echo "</pre>";
}
I am using the same server for both cases and I have installed/enabled SQLSRV. Please find the phpinfo screenshots for reference.
Why it is working in PHP file but not in the Laravel. Please help.
Note : MSSQL database is installed on another AWS windows Instance and TCP is enabled, and port number is 1433
Here is the error what I am getting,
Finally, able to figure out the issue, Posting the same so it will help someone who has struck for days and ripping their hair out to find the solution.
Change the below .env variables and database config as below,
MSSQL_ENCRYPT=yes
MSSQL_TRUSTSERVER=True
config/database.php
'trust_server_certificate' => env('MSSQL_TRUSTSERVER', true), //Some libraries accessing ODBC/JBDC require Yes/No settings, others True/False,
'encrypt' => env('MSSQL_ENCRYPT', 'yes'), //same here try Yes/No or True/False

connection to localhost works but not ip

If I connect to the database using 'localhost' as hostname, It works
$flag = [
'database_host' => 'localhost',
'database_port' => '',
'database_name' => 'dbdemo',
'database_user' => 'userdemo',
'database_password' => 'uijk',
'database_table' => 'tabledemo',
];
$link = mysqli_connect($flag['database_host'],$flag['database_user'],$flag['database_password'],$flag['database_name']);
But when I set up the hostname by using his ip (which I get through echo $_SERVER['SERVER_ADDR'];), It returns the error
Connection refused
I'm confused, is it not basicaly the same thing?

Echofish Error 500 "CDbConnection failed to open the DB connection"

I have to test Echofish to centralize log files.
I followed the installation procedure , but this one does not seem up to date.
When that connects me to the web interface , I get an error 500 - "CDbConnection failed to open the DB connection."
Error 500 in Echofish
When manually connects me to the database with " mysql -u echofish -p ETS_echofish ", it's works.
I changed the file db.php following documentation.
<?php
return array(
'connectionString' => 'mysql:host=localhost;port=3306;dbname=ETS_echofish',
'emulatePrepare' => true,
'username' => 'echofish',
'password' => 'my_password',
'charset' => 'utf8',
);
I use CentOS 7
Echofish uses Yii
Thanks
Please try this
<?php
return array(
'connectionString' => 'mysql:host=localhost;port=3306;dbname=ETS_echofish',
'emulatePrepare' => false,
'username' => 'echofish',
'password' => 'my_password',
'charset' => 'utf8',
);
Found the following solution which avoided disabling SELinux: Connect DATABASE Error TYPE: 2002: Permission denied
Basicly setsebool -P httpd_can_network_connect_db 1
That solved my problem. Hope it helps.

SwiftMailer Connection could not be established with host

I am getting an unexpected problem with emails being sent from my site. It had been working fine for some time and all of a sudden seems to have stopped for no apparent reason.
[Swift_TransportException] exception 'Swift_TransportException' with message 'Connection could not be established with host [Connection timed out #110]' in vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:265
In my web.php
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'mail.website.com',
'username' => 'username',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
What could have happened for this to stop working and how should I be fixing it?
I am using google apps for my emails, but I have always used this config where I connect to my mail server. I'm not sure why it suddenly stopped working.
Same thing thing happened to me in yii , couple of days ago.Solved it by changing the port.
Try,
'port' => 26,
it's looking for the server mail.website.com but isn't able to resolve it.
use this domain smtp.gmail.com and port 25 or 465.
if (!$this->_stream = fsockopen($host, $this->_params['port'], $errno, $errstr, $timeout))
{
throw new Swift_TransportException(
'Connection could not be established with host ' . $this->_params['host'] .
' [' . $errstr . ' #' . $errno . ']'
);
}
So you either need to input a valid smtp server or wrap the send() line in a try/catch to catch the exception and either log it somewhere or ignore it.
Please checkif the port you use is really the port used by your mail server.

unable to connect to Google Cloud Connection Server

I'm trying to open a XMPP connection between my server and the Google Cloud Connection Server (CCS), but it doesn´t work. I´m programming with PHP and using the JAXL library. Here is my code:
<?php
include_once 'jaxl.php';
$client = new JAXL(array(
'jid'=>'<my_sender_ID>#gcm.googleapis.com',
'pass'=>'my_API_key',
'auth_type'=>'PLAIN',
'host' => 'gcm.googleapis.com',
'port' => '5235',
'force_tls' => true
));
$client->start();
echo "done";
?>
And then I get this error:
unable to connect tcp://gcm.googleapis.com:5235 with error no: 110, error str: Connection timed out
what am I doing wrong?
You should connect to gcm.googleapis.com by ssl, not http or tcp.
I fixed this by modifying jaxl.php from:
public function get_socket_path() {
return ($this->cfg['port'] == 5223 ? "ssl" : "tcp")."://".$this->cfg['host'].":".$this->cfg['port'];
}
to:
public function get_socket_path() {
return ($this->cfg['port'] == 5223 || $this->cfg['ssl'] == true ? "ssl" : "tcp")."://".$this->cfg['host'].":".$this->cfg['port'];
}
After that you can initialize the client with:
$client = new JAXL(array(
'jid' => '<your-API-key>#gcm.googleapis.com',
'pass' => '<your-API-key>',
'host' => 'gcm.googleapis.com',
'port' => 5235,
'force_tls' => true,
'auth_type' => 'PLAIN',
'strict' => FALSE,
'ssl' => TRUE
));
Also, when you initialize the client, use
'log_level' => JAXL_DEBUG
That will allow you to see everything that's sending or being received. In my case, I figured out that my project has not yet been whitelisted - I forgot to register it on https://services.google.com/fb/forms/gcm/
jaxl_socket_client:189 - 2013-10-04 08:11:58 - <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><temporary-auth-failure/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Project 1012343798740 not whitelisted.</text></failure>
Perhaps you should change the host to http://gcm.googleapis.com. Your error says "unable to connect tcp://gcm.googleapis.com:5235".
GCM Cloud Connection Server (CCS) is an XMPP endpoint, running on http://gcm.googleapis.com port 5235.

Categories