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

Adebayo Ojo
Adebayo Ojo
23,661 Points

Fatal error: Class 'SMTP' not found in C:\wamp64\www\phpsite\inc\phpmailer\class.phpmailer.php on line 1466

I tried to send mail from my local server using PHPMailer, but getting this error. Below is my line 1466:

public function getSMTPInstance() { if (!is_object($this->smtp)) { $this->smtp = new SMTP; ----------> (line 1466) } return $this->smtp;

2 Answers

Simon Coates
Simon Coates
28,694 Points

have you included the full PHP Mailer library and included it's autoload file. Missing class might imply that SMTP is not defined at such time as you attempt to use it.

The tutorial series if i recall correctly only installed a single .php file from that library. So unless you've done a more comprehensive install than that demonstrated in the video, you may not have the necessary files and a correct import statement.

Adebayo Ojo
Adebayo Ojo
23,661 Points

I only included these 3 files: class.smtp.php, class.phpmailer.php and PHPMailerAutoload.php and still getting that error. Below is my suggest.php: (NOTE: My smtp server requires no authentication, no encryption and no authorization. Only uses port 25)

require("inc/phpmailer/class.phpmailer.php");

$mail = new PHPMailer;

if (!$mail->ValidateAddress($email)) { echo "Invalid Email Address"; exit; }

$email_body = ""; $email_body .= "Name " .$name . "\n"; $email_body .= "Email " .$email . "\n"; $email_body .= "Details " .$details . "\n";

$mail->Host = 'email.mycompany.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = false; // Enable SMTP authentication $mail->Username = ''; // SMTP username $mail->Password = ''; // SMTP password $mail->SMTPSecure = ''; // Enable TLS encryption, ssl also accepted $mail->Port = 25; // TCP port to connect to

$mail->setFrom($email, $name); $mail->addAddress('xyz@yahoo.com', 'Bayo'); // Add a recipient

$mail->isHTML(false); // Set email format to HTML

$mail->Subject = 'Personal Media Library Suggestion from ' . $name; $mail->Body = $email_body;

if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; }

Simon Coates
Simon Coates
28,694 Points

the PHP mailer class doesn't have access to the SMTP class. I think it's because you don't have an include statement that references the PHP mailer autoload. (I think PHP mailer gets access to the SMTP class through autoload mechanism)

Adebayo Ojo
Adebayo Ojo
23,661 Points

This is my include:

require("inc/phpmailer/class.phpmailer.php");

I followed the instruction in the video. Do I need to also include the PHPMailerAutoload.php?

Simon Coates
Simon Coates
28,694 Points

I think the video was a special case. Under ordinary circumstances, i think you're meant to download the whole thing and then require the autoloader. If you do this, you shouldn't need a separate include statement for phpmailer. This class should be provided as part of the autoload. Here's example code