We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phlacon mailer problem

Hi, I am using phalcon Mailer in a Phalcon module strcture. I have added a name space

namespace Phalcon\Mailer. I have store it library/mailer I have use namespace Phalcon\Mailer; for Manager.php

but I want to access it from /app/frontend/controllers/

use Phalcon\Mailer\Manager; in controller

$mail = new \Phalcon\Mailer\Manager($config);

but I got an error

"Fatal error: Class 'Phalcon\Mailer\Manager' not found in /Library/WebServer/Documents/biz_mela/apps/frontend/controllers/SessionController.php on line 610 "

Please any one give me any solutions

thanks



1.6k
edited Oct '14

make sure that you have registered the library in app/modules/frontend/Module.php

<?php
public function registerAutoloaders() {
        $config = include __DIR__ . "/../../config/config.php";
        $loader = new Loader();

        //register dir
        $loader->registerDirs(array(
            $config->application->pdf,
            $config->application->libraryDir,
            $config->application->pluginsDir
        ));

        $loader->register();
    }

/**
*   This is the config.php
*/

return new \Phalcon\Config(array(

    'application' => array(
        'controllersDir' => __DIR__ . '/../controllers/',
        'modelsDir' => __DIR__ . '/../models/',
        'viewsDir' => __DIR__ . '/../views/',
        'libraryDir' => __DIR__ . '/../library/',        
        'pluginsDir' => __DIR__ . '/../plugins/',
        'baseUri' => '/'
    )
));

yes but same

Fatal error: Class 'Phalcon\Mailer\Manager' not found in /Library/WebServer/Documents/biz_mela/apps/frontend/controllers/SessionController.php on line 611



1.6k

please print your class here,

<?php
//in your class declaration remove the 'Phalcon' from namespace and just leave 'Mailer';

//in library/mailer/Manager.php
namespace Mailer;
class Manager 
{...}

/*
* And from controller call it like this
*/

$manager = new \Mailer\Manager();

that error has been resolve but now showing

Service '\Swift_MailTransport' was not found in the dependency injection container that error

Installing

Install composer in a common location or in your project:

curl -s https://getcomposer.org/installer | php

Create the composer.json file as follows:

{
    "require": {
        "phalcon-ext/mailer": "~2.0"
    }
}

Run the composer installer:

php composer.phar install

Add in your the code

require_once('vendor/autoload.php');

use Phalcon\Ext\Mailer\Manager; in controller

$mail = new \Phalcon\Ext\Mailer\Manager($config);

that error has been resolve but now showing

Service '\Swift_MailTransport' was not found in the dependency injection container that error