Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Finding and Using Packages

David Marec
David Marec
9,578 Points

Fatal error with phpMailer class

Hi there,

I think i've done each step right (phpmailer install by composer, require autoload...) but when i try to send a mail, i have this error message :

Fatal error: Uncaught Error: Class 'PHPMailer' not found in /home/treehouse/workspace/email.php

This is happening in workSpace. Any help would be great !!

Thanks in advance ! David.

1 Answer

You should import the PHPMailer's classes into the global namespace, at the beginning of your code: use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception;

Or otherwise, you should instantiate the PHPMailer object like this: $mail = new PHPMailer\PHPMailer\PHPMailer();