Autoload PHP mailer is not working

1,622 views
Skip to first unread message

Muhammad Shahzad

unread,
Oct 23, 2017, 2:22:37 AM10/23/17
to Fat-Free Framework
Hi,

I'm facing "Fatal error: Class 'PHPMailer\PHPMailer\PHPMailer' not found", I have downloaded php mailer library from here:
https://github.com/PHPMailer/PHPMailer and put it into lib/vendor/phpmailer and when I want to create a object of PHPMailer class it show me error class not found.
Is something am I doing wrong?

In my index.php lib is included in autoloader like this:

    $f3->mset(array(
       
...
       
"AUTOLOAD" => "app/;../fatfree/lib/vendor/",


and in test controller I'm creating object like this:

namespace Controller;

use \PHPMailer\PHPMailer\PHPMailer;
use \PHPMailer\PHPMailer\Exception;

class Test extends \Controller {

   
public function index($f3){

        $mail
= new PHPMailer(true);
   
}

}


ved

unread,
Oct 23, 2017, 7:29:08 AM10/23/17
to Fat-Free Framework
Don't really know the answer to that issue, but it's most likely an issue with paths and/or namespaces and/or some conflict with F3's autoloader.

I would suggest that you load F3 and all other external libs using Composer which will make that and pretty much all path and namespace issues obsolete.

Rayne

unread,
Oct 23, 2017, 4:22:28 PM10/23/17
to Fat-Free Framework
I don't understand why you would add third party code to Fat-Free's directory.

PHPMailer 6 is not compatible with F3's autoloader as it doesn't provide a 1:1 mapping of its namespace to a directory hierarchy. If you want to use F3's autoloader you have to create a PHPMailer/PHPMailer directory and copy the content of src to that new directory.

PHPMailer 5 (https://github.com/PHPMailer/PHPMailer/tree/5.2-stable) is also not compatible with F3's autoloader but it provides an own loader:

require_once "PHPMailerAutoload.php";


I would recommend to use the latest version (6) with Composer instead.

Muhammad Shahzad

unread,
Oct 24, 2017, 2:16:07 AM10/24/17
to Fat-Free Framework

Hi,

I want to use this because of its advance code and functionality but now I have decided to not use.

Thanks

Roy H.G.

unread,
Nov 23, 2017, 2:36:11 PM11/23/17
to Fat-Free Framework
The simplest is using composer to install,

The others you should check the format folder you store PHPMailer it should align with namespace and it's case sensitive.

Reply all
Reply to author
Forward
0 new messages