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!

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 Build a Basic PHP Website (2018) Adding a Basic Form Using A Third-Party Library

7,197 Points

Is video up to date? No class file as described by Alena in the .zip.

I downloaded the zip as described from Github and there is no class file as described by Alena in the video. Am I missing something or is this not how to install it anymore?

7,197 Points

Okay so looks like PHPMailer had a significant update since this video was made.

I was able to get it working (so far!) via the new updated code - I have it working thus far with it set up like this - but any suggestions / edits would be appreciated since am still new to this stuff. Right now this works on my localhost and actually sends the email to my gmail account (though it goes to Spam XD )

Important notes are you now need require a few more files - the class.phpmailer.php file is now under a different name, etc. And when building the object you need to use that PHPMailer\PHPMailer\PHPMailer syntax.

Hopefully this helps others who may be stumbling in here. There is a more full explanation and changes to syntax of the upgrades from the old version (from the video) to the newer one on the PHPMailer Github .


    $mail = new PHPMailer\PHPMailer\PHPMailer;

    if (!$mail->ValidateAddress($email)) {
        echo "Invalid Email Address";
    // building up the email body
    $email_body = "";
    $email_body .= "Name " . $name . "\n";
    $email_body .= "Email " . $email . "\n";
    $email_body .= "Details " . $details . "\n";
    $mail->setFrom($email, $name);
    $mail->addAddress('my_sample_example_email@gmail.com', 'yourname'); 
    $mail->Subject = 'Personal Library Suggestion from ' . $name;
    $mail->Body    = $email_body;

    if (!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
Andrew Patella
Andrew Patella
2,270 Points

Super helpful THANK YOU!

Sam Gord
Sam Gord
14,084 Points


2 Answers

Jon Berkner
Jon Berkner
10,002 Points

Great!!!! One more thing, if you are using the treehouse workspace you need to send to the localhost. However, the video has

  $mail->addAddress('treehouse@localhost', 'your name');

which will return the error:

Message could not be sent.Mailer Error: You must provide at least one recipient email address.

You must update the address to include localdomain as:

  $mail->addAddress('treehouse@localhost.localdomain', 'your name');
Adrian Keedle
Adrian Keedle
Courses Plus Student 15,318 Points

this has taken me FIVE Days of Pain! I gave up and decided to go through step by step and look at every teachers note.... if i had only scrolled a little further on this question. Jon Berkner amazing thanks! Alena Holligan please please can you update.

Cliff Jackson
Cliff Jackson
2,887 Points

Has this video still not been updated...i am about to do this section??