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 Build a Basic PHP Website (2018) Enhancing a Form Specifying Required Fields

Attila Balog
Attila Balog
5,217 Points

i figured out how to send through gmail account.

i know how to test sending emails, if you don't work through Workspace. if anybody interested, leave comment here.

6 Answers

Attila Balog
Attila Balog
5,217 Points

'''php // Sending an email to any email address from your Gmail account!!!

require("inc/phpmailer/PHPMailerAutoload.php"); //or select the proper destination for this file if your page is in some   //other folder
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465"); //No further need to edit your configuration files.
$mail = new PHPMailer();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPSecure = "ssl";
$mail->Username = "your account@gmail.com"; //my account name
$mail->Password = "your pass"; //this account's password.
$mail->Port = "465";
$mail->isSMTP();  // telling the class to use SMTP
$rec1="recepient@gmail.com"; //receiver. email addresses to which u want to send the mail.
$mail->AddAddress($rec1);


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

This is awesome.. thank you

Brian Patterson
Brian Patterson
19,588 Points

This worked. Just remember is anyone is looking to push a project to Github remember to take your email details out.

phillipandroiddev
phillipandroiddev
14,987 Points

Thank you for sharing. I appreciate it.

Thanks a lot! Great Help!

My Linh Nguyen
My Linh Nguyen
1,847 Points

Btw, if someone tried this and I did not work, you can change your gmail setting, I change my gmail setting to allow SMTP, and I worked use our clone email for security reason

Alvin Hue
Alvin Hue
4,496 Points

Thanks for the solution Attila Balog!

However I am still not able to get things fixed, I received this "Fatal error: Class 'SMTP' not found in C:\xampp\htdocs\php\basic\inc\phpmailer\class.phpmailer.php on line 1520" after I submitted the form, anyone have any ideas how to solve this?

Big thanks ya!

Santiago Martinez
Santiago Martinez
5,764 Points

Check if this works for you but inside the phpmailer that we downloaded from github, there is a php file called class.smtp.php. Just drag that file into your inc/phpmailer folder and it should look like below inc/phpmailer/class.smtp.php

This should work since I was having the same problem and hopes it help you.