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

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?



85.5k
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 ?



77.7k
Accepted
answer
edited Oct '15

https://docs.phalcon.io/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.



1.5k
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 >.>



1.5k

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.