Bogosta Pavlo
Bogosta Pavlo

Reputation: 1

Adding external libs to the Phalcon project

Cannot add the Phalcon mailer and use it in the project. Doing same as instructions say. I have config linking to 'libraryDir' => APP_PATH . '/app/lib/', in the lib folder I have a Mailer folder where I put the composer.json.

I followed THIS but after using the lib in the Controller I've got

Fatal error: Uncaught Error: Class 'Phalcon\Ext\Mailer\Manager'

Code :

use Phalcon\Http\Response; 
use Phalcon\Mvc\Model\Criteria; 
use Phalcon\Mvc\Model\Query\BuilderInterface; 
use Phalcon\Di\InjectionAwareInterface; 
use Phalcon\Mvc\Model\Resultset; use Phalcon\Ext\Mailer\Manager; 
use Phalcon\Ext\Mailer\Message;

class EmailController extends Phalcon\Mvc\Controller { 
public function initialize() { 
if ($this->request->isPost()) { 
$this->view->disable(); 
} 
}
public function indexAction() {

}

public function sendEmailAction(){
    if ($this->request->isPost()) {

        $config = [
            'driver'   => 'mail',
            'from'         => [
                'email' => '[email protected]',
                'name'    => 'Email'
            ]
        ];

        $email = new Phalcon\Ext\Mailer\Message($config);
        return "send";
    }
}
}

Upvotes: 0

Views: 506

Answers (2)

user1855153
user1855153

Reputation: 579

@klay answer is right. I see they actually ask to create a composer.json on their README. But I do agree to use composer require instead:

composer require "phalcon-ext/mailer":"~2.1"

You can also use the phalcon loader to register your autoload file while you register other things.

$loader = new Loader();
$loader->registerFiles('../vendor/autoload.php');

If you need more help, I'd suggest to read the composer documentation

Upvotes: 1

serghei
serghei

Reputation: 3381

You have to follow Phalcon\Ext\Mailer installation instructions. There is no instructions about putting somewhere composer.json. Just install this library using typical for the Composer way:

composer require "phalcon-ext/mailer":"~2.0"

The last thing you need: make sure that you are using Composer autoloader:

require_once 'vendor/autoload.php';

Upvotes: 0

Related Questions