I am new to Lumen, Can some one tell me how to set up FTP in lumen. I have tried with below code set up but it is not working at my end - lumen

I am using lumen 9.0.
$response = Storage::disk('ftp')->put('path-to-remote-server', $fileContent)
In $response i am getting 1(true) as response but file is not uploading to remote server.
My filesystem.php
'ftp' => [
'driver' => 'sftp',
'host' => 'host-ip',
'username' => '****',
'password' => '****',
],
My Composer Json has below library installed
"league/flysystem-sftp-v3": "^3.0",
"phpseclib/phpseclib": "^3.0"

Related

How to set up a smtp connection on a domain email in laravel

I have a domain: www.mydomain.ro and i created an email like this: office#mydomain.ro
I'm trying to send emails from my laravel application(laravel 5.7) and i did this configurations:
In .env file:
MAIL_DRIVER=smtp
MAIL_HOST=office#my-domain.ro
MAIL_PORT=26
MAIL_USERNAME=office#my-domain.ro
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=null
And in config/mail.php:
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'mail.my-domain.ro '),
'port' => env('MAIL_PORT', 26),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'office#muy-domain.ro'),
'name' => env('MAIL_FROM_NAME', 'Office my-domain'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('office#my-domain.ro'),
'password' => env('mypassword'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
In Controller i'm doing this:
$data = array(
'name' => 'Ioan Andrei',
'body' => 'Test Email'
);
Mail::send('emails.demandreceived',$data,function ($message){
$message->from('office#my-domain.ro','TEST');
$message->to('ioan.andrei97#gmail.com');
$message->subject('Test email');
I get this error:
Connection could not be established with host office#msipremiumcars.ro [php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known #0]
What am i doing wrong?It's not working beacuse i'm trying to send them from my local server?
Can i use mailgun for example to send the email and still have the email send from office#mydomain.ro?
I tried to restart my local server after configs.
Laravel version: 5.7
The issue is the MAIL_HOST in the .env file. It needs to be hostname like my-domain.ro instead of an email address as you've currently entered office#my-domain.ro.

yii2 mailer smtp connection refused

When setting up my smtp mailer in the config file, it works fine. But if I manually create the SMPT mailer it fails (Connection refused). Can anybody assist?
Yii2 config file:
'components'=[
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email#gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
The following code in my controller does not work:
$mailer = new \yii\swiftmailer\Mailer();
$mailer->transport = new \Swift_SmtpTransport();
$mailer->transport
->setHost('smtp.gmail.com')
->setPort(587)
->setEncryption('tls');
$mailer->transport->setUsername('email#gmail.com');
$mailer->transport->setPassword('password');
and I receive an error message: Connection refused #111
I have tried port 465 on ssl and I receive the same message.
My main reason for doing this is that I have different client accounts, each of which has its own smtp. I therefore need one account per client and I cannot seem to do that via the config file.
Many thanks for your help.
I just tried it worked for me, I did as follow
'components'=[
'mailer' => [ //Your default mailer
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email#gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
],
'mailer2' => [ //Your custom mailer
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'new_email#gmail.com',
'password' => 'new_password',
'port' => 'new_port587',
'encryption' => 'new_tls',
],
]
following is for default config
Yii::$app->mailer->compose()
->setFrom('info#gmail.com')
->setTo('xxx#gmail.com')
->setSubject('Subject')
->setTextBody('Plain text content')
->setHtmlBody("Hello")
->send();
following with custom mailer config
Yii::$app->mailer2->compose()
->setFrom('info#gmail.com')
->setTo('xxx#gmail.com')
->setSubject('Subject')
->setTextBody('Plain text content')
->setHtmlBody("Hello")
->send();
create a component is the fastest solution, otherwise, you can use the parameter to store configuration, and call when needed.

SQLSTATE[HY000] [1045] Access denied for user - OVH Eloquent

For a project I use Slim 3 - Twig and Eloquent. On development mode, all works perfectly, but on production, hosted in the OVH shared server, I can't access to the database.
I'm hundred percent sure of credentials and the database was not created right now.
This is my code :
$capsule = new \Illuminate\Database\Capsule\Manager;
$capsule->addConnection($config['db']);
$capsule->bootEloquent();
$capsule->setAsGlobal();
Where $config['db'] contains the informations required by Eloquent :
$config = [
'settings' => [
'debug' => true,
'displayErrorDetails' => true
],
'db' => [
'driver' => 'mysql',
'host' => '****.mysql.db',
'database' => '****',
'username' => '****',
'password' => '****',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
]
]
What I have to do to make it work ?
Ok ... I get the solution.
... Suspense ...
I have to remove spaces around the big arrows in my beautiful formatted array.
Yes. I'm gonna cry.

Connect With PostgreSQL in Phalcon Framework

Phalcon is not able to connect to postgrsql. Here are my settings in config.php
return new \Phalcon\Config(array(
'database' => array(
'adapter' => 'Postgresql',
'host' => 'localhost',
'username' => 'postgres',
'password' => 'root',
'dbname' => 'mydb',
'charset' => 'utf8',
),
'application' => array(
'controllersDir' => __DIR__ . '/../../app/controllers/',
'modelsDir' => __DIR__ . '/../../app/models/',
'viewsDir' => __DIR__ . '/../../app/views/',
'pluginsDir' => __DIR__ . '/../../app/plugins/',
'libraryDir' => __DIR__ . '/../../app/library/',
'cacheDir' => __DIR__ . '/../../app/cache/',
'baseUri' => '/test/',
)
));
Page is blank showing no errors.
DI service implementation
use Phalcon\Db\Adapter\Pdo\Postgresql as DbAdapter;
$di->set('db', function () use ($config) {
return new DbAdapter(array(
'host' => $config->database->host,
'username' => $config->database->username,
'password' => $config->database->password,
'dbname' => $config->database->dbname,
"charset" => $config->database->charset
));
});
There is no port in db connection array you used. Default postgresql port is 5432. so use this in your db connection and try to pass array directly to postgresql adapter constructor.
or
install postgres pdo /php pdo again.
I think that code is fine.
I was working a project where i had to use MySQL and PostGres.I connected my Postgresdb by following-
Below default 'db' connection string i wrote the following code inside services.php-
$di->setShared('pgphalcon', function () {
$config = $this->getConfig();
$adaptar = "PostgreSQL";
$class = 'Phalcon\Db\Adapter\Pdo\\' . $adaptar;
$params = [
'host' => "localhost",
'port' => "5432", // for localhost no need to put this line unless u change the port
'username' => "postgres",
'password' => "12345",
'dbname' => "phalcon",
];
$connection = new $class($params);
return $connection;
});
Then your controller function
do the following-
public function yourcontrollernameAction()
{
$con = $this->di->get('pghalcon');
$post = $con->fetchOne("SELECT * FROM blog ORDER BY id DESC LIMIT 1", Phalcon\Db::FETCH_ASSOC);
$this->view->data= $post;
}
For better Understanding I'd like to suggest visit this url
One thing to clarify- I was failed to do db operation by Model for PostGreSQL. That's why I used this way.

how to connect to the database in zend with dsn line

zend framework 1.x
how to receive zend db_adapter and connect to mysql having dsn like
mysql://john:pass#localhost:3306/my_db
previously was always using this way:
$connectParams = array('dbname' => MY_DB,
'password' => MY_PASS,
'username' => MY_USER,
'host' => MY_HOST,
'slave' => array(),
'maxQueryAllowedTime' => 500,
'logQueries' => false);
return new \Db_Adapter_Pdo_Mysqlreplicator($connectParams);
sure i can parse dsn and use usual way, just curious if i can use DSN directly, coz PDO can use it but i cant find how to use it through Zend Db_Adapter
If you are using ZendFramework 1.x ->Try this:-
$config = array('dbname' => 'yourDbName',
'password' => 'yourpassword',
'username' => 'root',
'host' => 'localhost',
'slave' => array(),
'maxQueryAllowedTime' => 500,
'logQueries' => false);
$adapter = new Zend_Db_Adapter_Mysqli($config);
if ($config) {
echo ' connected';
}