Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Phalcon Loader PHPMailer

Hey,

so im using the registerDirs option.

My self created classes get loaded well and work. But once i throw in the PHPMailer folder and try to create a new one i get a 500 error.

<?php

class IndexController extends ControllerBase
{
    public function indexAction()
    {
        $mail = new PHPMailer();
    }

https://github.com/PHPMailer/PHPMailer

Has anyone an idea what im doing wrong here?



64.3k
edited Oct '15

hmm, sorry if I am being stupid, can you try

$mail = new \PHPMailer();

and also do you use composer for the instaltion ?



38.6k
Accepted
answer
edited Oct '15

https://docs.phalconphp.com/en/latest/reference/loader.html#registering-directories

When using Phalcon Loader, class names must match filenames. You could use composer, or require_once "PATH_TO_PHPMAILER/PHPMailerAutoload.php"; where you register Phalcon Loader.



525
edited Oct '15

Thanks for the fast answers.

$mail = new \PHPMailer();

had no effect.

I tried require_once "../library/PHPMailer/PHPMailerAutoload.php"; before and after initializing the loader. The require_once itself causes a 500.

What do you mean by using composer? I thought composer is just a packet manager.

I guess i have to get the damn error reporting to work. Apache is loading a hundred php.inis >.>



525

Error reporting ftw!

require_once does the job for now. Thanks Lajos.

  1. I think its better to use Swift Mailer.
  2. Create a service and in it require_once library.
  3. If you sending a lot of mails(for exmaple in foreach) - use a queue and cron task.