I have external library handling connection to mail delivery system. Its just php class. How do i include and use this class inside craft plugin controller?


class mail_delivery{


namespace Craft;

class controller extends BaseController

    public function init()
        require_once 'library.php';

    public function method(){
        $object = $rest = new mail_delivery();

I get PHP error:

( ! ) Fatal error: Class 'Craft\FmRestAPI' not found in C:\xampp\htdocs\mmimport\craft\plugins\freshmailintegration\controllers\FreshmailIntegration_EmailController.php on line 27

Is this some kind of namespace issue?

1 Answer 1


Is this some kind of namespace issue?

Yes. If the class you're trying to instantiate is in a namespace, you'd need to indicate that:

$object = $rest = new \the\library\class\namespace\mail_delivery();

If it does not use namespaces, it's probably in the global namespace:

$object = $rest = new \mail_delivery();

If you do it like in your example:

$object = $rest = new mail_delivery();

Then PHP will assuming it's in the current file's namespace (Craft) and you'll get the error that you see.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.